RHEL 7.2 安装 MySQL 5.7.11 二进制版

操作系统:rhel7.2

MySQL版本:5.7.11

1、MySQL下载

http://dev.mysql.com/downloads/

2、上传MySQL软件到操作系统

[root@rhel7 ~]# ls -l mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--. 1 root root 548193637 Dec  4 21:16 mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz

3、添加mysql用户和组

[root@rhel7 ~]# groupadd mysql
[root@rhel7 ~]# useradd -r -g mysql -s /bin/false mysql
[root@rhel7 ~]# id mysql
uid=996(mysql) gid=1000(mysql) groups=1000(mysql)

4、创建目录、改属组及解压文件

[root@rhel7 ~]# mkdir -p /opt/mysql/
[root@rhel7 ~]# mkdir /mysqldata
[root@rhel7 ~]# mv /root/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz /opt/mysql/
[root@rhel7 ~]# cd /opt/mysql/
[root@rhel7 mysql]# ls
mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
[root@rhel7 mysql]# tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
......
[root@rhel7 mysql]# mv mysql-5.7.11-linux-glibc2.5-x86_64 mysql5.7.11
[root@rhel7 mysql]# ls -l
total 535352
drwxr-xr-x. 9 7161 wheel      4096 Feb  2  2016 mysql5.7.11
-rw-r--r--. 1 root root  548193637 Dec  4 21:16 mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
[root@rhel7 mysql]# chown mysql:mysql -R /opt/mysql/
[root@rhel7 mysql]# chown mysql:mysql -R /mysqldata/

5、初始化库

[root@rhel7 mysql]# cd mysql5.7.11/
[root@rhel7 mysql5.7.11]# ./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql/mysql5.7.11/ --datadir=/mysqldata/
2016-12-04T13:33:01.318081Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-12-04T13:33:01.729086Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-04T13:33:02.027182Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-12-04T13:33:02.111882Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2dca0cf3-ba26-11e6-b4ff-080027e818bc.
2016-12-04T13:33:02.118970Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-12-04T13:33:02.120080Z 1 [Note] A temporary password is generated for root@localhost: rqwPw!9iNEEP
[root@rhel7 mysql5.7.11]# ls /mysqldata/
auto.cnf  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  sys

注意:root的初始密码已经在日志中给出:rqwPw!9iNEEP

在5.7.6之前的版本中使用bin/mysql_install_db --user=mysql初始化库。

6、启动MySQL数据库

#替换系统自带的my.cnf文件
[root@rhel7 mysql5.7.11]# mv /etc/my.cnf /etc/my.cnf.bak
[root@rhel7 mysql5.7.11]# cp support-files/my-default.cnf /etc/my.cnf
#在my.cnf中添加如下两条
[root@rhel7 mysql5.7.11]# vi /etc/my.cnf
basedir = /opt/mysql/mysql5.7.11
datadir = /mysqldata
#启动MySQL
[root@rhel7 mysql5.7.11]# ./bin/mysqld_safe --user=mysql &
[1] 1756
[root@rhel7 mysql5.7.11]# 2016-12-04T13:44:30.046089Z mysqld_safe Logging to '/mysqldata/rhel7.err'.
2016-12-04T13:44:30.097978Z mysqld_safe Starting mysqld daemon with databases from /mysqldata
 
[root@rhel7 mysql5.7.11]# ps -ef |grep mysql
root      1756  1182  0 21:44 pts/0    00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql
mysql    1876  1756  1 21:44 pts/0    00:00:00 /opt/mysql/mysql5.7.11/bin/mysqld --basedir=/opt/mysql/mysql5.7.11 --datadir=/mysqldata --plugin-dir=/opt/mysql/mysql5.7.11/lib/plugin --user=mysql --log-error=/m
ysqldata/rhel7.err --pid-file=/mysqldata/rhel7.pidroot      1905  1182  0 21:44 pts/0    00:00:00 grep --color=auto mysql

7、登录MySQL,使用安装时给出密码登录并更改root密码

注意:5.6之前使用set password=password('newpassword')进行改密码,5.7版本不再建议这样改密码,会有如下提示:

mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> show warnings;
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level  | Code | Message                                                                                                                                                          |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | 'SET PASSWORD = PASSWORD('<plaintext_password>')' is deprecated and will be removed in a future release. Please use SET PASSWORD = '<plaintext_password>' instead |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

到此,MySQL5.7.11安装完成。

官方文档:http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

猜你喜欢

转载自www.linuxidc.com/Linux/2016-12/137904.htm
今日推荐