1. 解压到 /usr/local
# tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
2. 重命名
# cd /usr/local/
# mv mysql-5.7.17-linux-glibc2.5-x86_64/ mysql
3. 创建用户
建立用户mysql,组mysql。后面mysql就使用这个用户来运行(注意这也是mysql启动脚本中默认的用户,因此最好不要改名)。
#groupadd mysql
#useradd -r -g mysql mysql (使用-r参数表示mysql用户是一个系统用户,不能登录)
建立目录/data/mysql/data,后面mysql就安装在这个目录下面。
#mkdir /data/mysql/data
4. 初始化操作(生成初始密码):
先要创建 /data/mysql/data 目录
# cd /usr/local/mysql
# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
如果报错:"./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No"
解决方法:"#yum install -y libaio"
最后一条是初始密码:
2018-03-21T13:24:18.219883Z 1 [Note] A temporary password is generated for root@localhost: jIhNzbsnC0.g
5. 创建配置文件 my.cnf
1. 将默认生成的my.cnf备份
[root@localhost etc]# mv /etc/my.cnf /etc/my.cnf.bak
[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
2. 配置
将mysql/support-files下的my-default.cnf改名为my.cnf,拷到/etc下(或者考到{mysql}下,然后作一个软链接到/etc下):
#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
my.cnf中关键配置:
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql/data
port = 3306
server_id = 1
[client]
socket=/data/mysql/data/tmp/mysql.sock
注意,/data/mysql/data/tmp目录不存在,请创建之。
6. 加入MySQL为系统服务:
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# chkconfig --list|grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost mysql]#chmod 755 /etc/init.d/mysqld
7. 设置环境变量:
[root@localhost mysql]# vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost mysql]# source /etc/profile
8. 检查MySQL是否能开启
[root@localhost mysql]# service mysqld start;
Starting MySQL.. [ OK ]!
问题1: 若改用了, 则在启动服务时会出现如下错误:
# ./support-files/mysql.server start
./support-files/mysql.server: line 276: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
这时候我们需要修改/support-files/mysql.server文件的basedir和datadir目录路径为我们正确的mysql的basedir和datadir路径, 如下:
# vim support-files/mysql.server 注意:修改后,再复制到#cp support-files/mysql.server /etc/init.d/mysqld
--------------------------
...
basedir=/usr/local/mysql
datadir=/data/mysql/data
...
--------------------------
# ./support-files/mysql.server start
Starting MySQL.. SUCCESS!
问题2: [root@imango mysql]# service mysqld start
Starting MySQL...The server quit without updating PID file (/data/mysql/data/imango.localdomain.pid).[FAILED]
如果出现上面的错误,表示data目录没有权限:
[root@imango mysql]# chown -R mysql:mysql /data
[root@imango mysql]# chown -R mysql:mysql /data/mysql/
[root@imango mysql]# chown -R mysql:mysql /data/mysql/data/
[root@imango mysql]# chown -R mysql:mysql /data/mysql/data/tmp/
10、登录MySQLPlus修改密码
[root@tobin tmp]# mysql -uroot -pjIhNzbsnC0.g
mysql> set password=password("123456");
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456'; // 让所有IP都能进入访问
--------------
mysql Ver 14.14 Distrib 5.7.17, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 12
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.17 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /data/mysql/data/tmp/mysql.sock
Uptime: 9 min 28 sec
Threads: 3 Questions: 38 Slow queries: 0 Opens: 235 Flush tables: 1 Open tables: 228 Queries per second avg: 0.066
--------------
# tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
2. 重命名
# cd /usr/local/
# mv mysql-5.7.17-linux-glibc2.5-x86_64/ mysql
3. 创建用户
建立用户mysql,组mysql。后面mysql就使用这个用户来运行(注意这也是mysql启动脚本中默认的用户,因此最好不要改名)。
#groupadd mysql
#useradd -r -g mysql mysql (使用-r参数表示mysql用户是一个系统用户,不能登录)
建立目录/data/mysql/data,后面mysql就安装在这个目录下面。
#mkdir /data/mysql/data
4. 初始化操作(生成初始密码):
先要创建 /data/mysql/data 目录
# cd /usr/local/mysql
# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
如果报错:"./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No"
解决方法:"#yum install -y libaio"
最后一条是初始密码:
2018-03-21T13:24:18.219883Z 1 [Note] A temporary password is generated for root@localhost: jIhNzbsnC0.g
5. 创建配置文件 my.cnf
1. 将默认生成的my.cnf备份
[root@localhost etc]# mv /etc/my.cnf /etc/my.cnf.bak
[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
2. 配置
将mysql/support-files下的my-default.cnf改名为my.cnf,拷到/etc下(或者考到{mysql}下,然后作一个软链接到/etc下):
#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
my.cnf中关键配置:
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql/data
port = 3306
server_id = 1
socket = /data/mysql/data/tmp/mysql.sock
character-set-server = utf8
[client]
socket=/data/mysql/data/tmp/mysql.sock
注意,/data/mysql/data/tmp目录不存在,请创建之。
6. 加入MySQL为系统服务:
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# chkconfig --list|grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost mysql]#chmod 755 /etc/init.d/mysqld
7. 设置环境变量:
[root@localhost mysql]# vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost mysql]# source /etc/profile
8. 检查MySQL是否能开启
[root@localhost mysql]# service mysqld start;
Starting MySQL.. [ OK ]!
问题1: 若改用了, 则在启动服务时会出现如下错误:
# ./support-files/mysql.server start
./support-files/mysql.server: line 276: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
这时候我们需要修改/support-files/mysql.server文件的basedir和datadir目录路径为我们正确的mysql的basedir和datadir路径, 如下:
# vim support-files/mysql.server 注意:修改后,再复制到#cp support-files/mysql.server /etc/init.d/mysqld
--------------------------
...
basedir=/usr/local/mysql
datadir=/data/mysql/data
...
--------------------------
# ./support-files/mysql.server start
Starting MySQL.. SUCCESS!
问题2: [root@imango mysql]# service mysqld start
Starting MySQL...The server quit without updating PID file (/data/mysql/data/imango.localdomain.pid).[FAILED]
如果出现上面的错误,表示data目录没有权限:
[root@imango mysql]# chown -R mysql:mysql /data
[root@imango mysql]# chown -R mysql:mysql /data/mysql/
[root@imango mysql]# chown -R mysql:mysql /data/mysql/data/
[root@imango mysql]# chown -R mysql:mysql /data/mysql/data/tmp/
[root@imango mysql]# service mysqld start
Starting MySQL.[ OK ]10、登录MySQLPlus修改密码
[root@tobin tmp]# mysql -uroot -pjIhNzbsnC0.g
mysql> set password=password("123456");
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456'; // 让所有IP都能进入访问
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \s--------------
mysql Ver 14.14 Distrib 5.7.17, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 12
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.17 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /data/mysql/data/tmp/mysql.sock
Uptime: 9 min 28 sec
Threads: 3 Questions: 38 Slow queries: 0 Opens: 235 Flush tables: 1 Open tables: 228 Queries per second avg: 0.066
--------------