mysql5.7的二进制编译包安装方法与5.6版本有些地方不同,下面将安装方法记录,方便后期查看
解压并移动目录至/usr/local,重命名为mysql5.7
[root@localhost src]# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
[root@localhost src]# mv mysql-5.7.17-linux-glibc2.5-x86_64 ../mysql5.7
创建目录,修改权限
[root@localhost mysql5.7]# mkdir /data/mysql5.7/ [root@localhost mysql5.7]# chown -R mysql.mysql /data/mysql5.7/
初始化
[root@localhost mysql5.7]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql5.7 2017-12-14T14:18:32.479547Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-12-14T14:18:32.479648Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2017-12-14T14:18:32.479655Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 2017-12-14T14:18:32.479775Z 0 [ERROR] Error message file '/usr/local/mysql/share/english/errmsg.sys' had only 886 error messages, but it should contain at least 1081 error messages. Check that the above file is the right version for this program! 2017-12-14T14:18:44.095382Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-12-14T14:18:48.210236Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-12-14T14:18:48.278351Z 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: b38a0c90-e0d9-11e7-97da-000c29d081f5. 2017-12-14T14:18:48.700210Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-12-14T14:18:48.703111Z 1 [Note] A temporary password is generated for root@localhost: xTA5l2(ATjof
最后这串字符"xTA5l2(ATjof"是mysql数据库初始化的root密码
创建密钥
[root@localhost mysql5.7]# ./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql5.7/ Generating a 2048 bit RSA private key ..................................+++ .............+++
writing new private key to 'ca-key.pem'
Generating a 2048 bit RSA private key ............................+++ ...........................+++
writing new private key to 'server-key.pem'
Generating a 2048 bit RSA private key ..............................+++ .............+++
writing new private key to 'client-key.pem'
修改配置文件(这里原本已经有/etc/my.cnf了,后续直接指定新的配置文件)
[root@localhost mysql5.7]# cp support-files/my-default.cnf /etc/my7.cnf [root@localhost mysql5.7]# vi /etc/my7.cnf 修改 basedir和datadir参数即可
命令行模式启动mysql5.7
[root@localhost mysql5.7]# ./bin/mysqld_safe --defaults-file=/etc/my7.cnf --user=mysql & [1] 5566 [root@localhost mysql5.7]# 2017-12-14T14:29:10.302174Z mysqld_safe Logging to '/data/mysql5.7/localhost.localdomain.err'. 2017-12-14T14:29:10.305015Z mysqld_safe Logging to '/data/mysql5.7/localhost.localdomain.err'. 2017-12-14T14:29:10.341094Z mysqld_safe Starting mysqld daemon with databases from /data/mysql5.7
验证
[root@localhost mysql5.7]# ps aux | grep mysqld root 5566 0.0 0.1 113268 1592 pts/0 S 22:29 0:00 /bin/sh ./bin/mysqld_safe --defaults-file=/etc/my7.cnf --user=mysql mysql 5685 5.6 12.8 1119056 183688 pts/0 Sl 22:29 0:00 ./bin/mysqld --defaults-file=/etc/my7.cnf --basedir=/usr/local/mysql5.7 --datadir=/data/mysql5.7 --plugin-dir=/usr/local/mysql5.7/lib/plugin --user=mysql --log-error=/data/mysql5.7/localhost.localdomain.err --pid-file=/data/mysql5.7/localhost.localdomain.pid root 5715 0.0 0.0 112676 976 pts/0 S+ 22:29 0:00 grep --color=auto mysqld
设置mysql密码
使用初始密码登录,并修改密码
[root@localhost mysql5.7]# /usr/local/mysql5.7/bin/mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.17
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit Bye
用新密码重新登录
[root@localhost mysql5.7]# /usr/local/mysql5.7/bin/mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
说明
如果当前系统已经运行了一个mysql,那么启动新配置的mysql5.7将回立即关闭。
[root@localhost mysql5.7]# 2017-12-14T14:27:52.822754Z mysqld_safe Logging to '/data/mysql5.7/localhost.localdomain.err'. Logging to '/data/mysql5.7/localhost.localdomain.err'. 2017-12-14T14:27:52.929283Z mysqld_safe Starting mysqld daemon with databases from /data/mysql5.7 2017-12-14T14:27:57.359819Z mysqld_safe mysqld from pid file /data/mysql5.7/localhost.localdomain.pid ended
[1]+ 完成 ./bin/mysqld_safe --defaults-file=/etc/my7.cnf --user=mysql
不知道mysql数据库root的密码
修改配置文件 vi /etc/my7.cnf 在[mysqld]下面加一行 skip-grant-tables 保存后重启mysql
修改密码 [root@localhost mysql5.7]# /usr/local/mysql/bin/mysql -uroot mysql> use mysql; mysql> update user set authentication_string=password('123333') where user='root';
重新修改配置文件,去除第1步添加的行
重启mysql服务生效
下载地址 http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz