创建MySQL组:
groupadd mysql
创建mysql用户并赋予这个mysq组中,不创建家目录,不允许用户登录。(因为刚刚创建的mysql是虚拟用户,所以不允许登录)
useradd mysql -g mysql -M -s /bin/nologin
源码安装mysql
解压后进行编译安装:
./configure \
--prefix=/application/mysql5.1.72 \
--with-unix-socket-path=/application/mysql5.1.72/tmp/mysql.sock \
--localstatedir=/application/mysql5.1.72/data \
--enable-assembler \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-big-tables \
--without-debug \
--with-pthread \
--enable-assembler \
--with-extra-charsets=complex \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static
make && make make install
安装好后 创建mysql的软链接:
ln -s /application/mysql5.1.72/ /application/apache
在该目录下查看/usr/local/tools/mysql-5.1.72/support-files/下面cnf的配置文件 这些文件都是默认的配置文件的模版,适合与不同的场景
[root@node1 support-files]# ll my*.cnf
-rw-r--r-- 1 root root 4746 05-04 02:49 my-huge.cnf 第四小 这些是根据服务器的硬件配置来衡量,服务器硬件过低,用最小的,配置高,用最大
-rw-r--r-- 1 root root 19779 05-04 02:49 my-innodb-heavy-4G.cnf 最大的
-rw-r--r-- 1 root root 4720 05-04 02:49 my-large.cnf 第三小
-rw-r--r-- 1 root root 4731 05-04 02:49 my-medium.cnf 最小的
-rw-r--r-- 1 root root 2499 05-04 02:49 my-small.cnf 第二小
然后将其中选择适合你的服务器的配置文件拷贝到/etc下
[root@node1 support-files]# cp my-small.cnf /etc/my.cnf
创建mysql数据库存放数据的目录:
[root@node1 ~]# mkdir /application/mysql/data -p
给/application/mysql/目录授予mysql用户和mysql组的权限
[root@node1 ~]# chown -R mysql.mysql /application/mysql/
初始化数据文件
[root@node1 ~]#/application/mysql/bin/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
plication/mysql/data/ --user=mysql
Installing MySQL system tables...
170504 4:34:50 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
170504 4:34:50 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/application/mysql//bin/mysqladmin -u root password 'new-password'
/application/mysql//bin/mysqladmin -u root -h node1.com password 'new-password'
Alternatively you can run:
/application/mysql//bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl
Please report any problems with the /application/mysql//scripts/mysqlbug script!
现在mysql就已经安装完成,到data目录下查看会生成两个库:
[root@node1 ~]# ll /application/mysql/data/
总计 8
drwx------ 2 mysql root 4096 05-04 04:34 mysql 系统的库,
drwx------ 2 mysql root 4096 05-04 04:34 test 测试的库,建议删除,不安全。
[root@node1 init.d]# /application/mysql//bin/mysqld_safe &
[1] 17071
[root@node1 init.d]# 170504 04:48:46 mysqld_safe Logging to '/application/mysql5.1.72/data/node1.com.err'.
170504 04:48:47 mysqld_safe Starting mysqld daemon with databases from /application/mysql5.1.72/data
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]# netstat -tulnp | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 17179/mysqld
启动mysql 以start方式启动
[root@node1 init.d]# cp /usr/local/tools/mysql-5.1.72/support-files/mysql.server /etc/init.d/mysqld
[root@node1 init.d]# chmod +x /etc/init.d/mysqld
保存之后就可以启动了。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| | localhost |
| root | localhost |
| | node1.com |
| root | node1.com |
+------+-----------+
5 rows in set (0.00 sec)
mysql> drop user ""@localhost
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ""@node1.com
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql>
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
| root | node1.com |
+------+-----------+
3 rows in set (0.00 sec)
衢江ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!
网页标题:源码安装mysql
浏览地址:http://lswzjz.com/article/jspdhg.html