一步一步教你如何在RHEL/CentOS上的安装MySQL 5.7

1. 从官网下载mysql5.7的安装包

http://dev.mysql.com/downloads/mysql/
下载下面几个即可,其它的可选

mysql-community-client-5.7.11-1.el6.x86_64.rpm
mysql-community-libs-5.7.11-1.el6.x86_64.rpm
mysql-community-common-5.7.11-1.el6.x86_64.rpm
mysql-community-server-5.7.11-1.el6.x86_64.rpm

下载后拷贝到目标机器的mysql5.7目录下

2.  安装mysql5.7

  1. cd mysql5.7
  2. rpm -ihv *.rpm –nodeps

注:我的环境不干净,装了多套MySQL。正常应该把上面的”–nodeps”去掉,或者用”yum install *.rpm”安装。

如果由于和已安装的mysql冲突失败,卸载冲突的旧版mysql再执行,比如:

  1. rpm -e mysql-libs-5.1.61 –nodeps
  2. rpm -e mysql-5.1.61 –nodeps

3. 根据环境修改配置文件

  1. vi /etc/my.cnf

4. 初始化数据库

  1. mysqld –initialize –user mysql

5. 启动数据库

  1. mysqld_safe &

6. 连接数据库并修改密码

  1. mysql -S /opt/mysql57_data/mysql.sock -uroot -pqXay8wk3RL*T -e “ALTER USER USER() IDENTIFIED BY ‘mysql'”

上面假设数据目录为”/opt/mysql57_data”,初始密码”qXay8wk3RL*T”,这两项需要根据实际情况修改。
初始密码可以在错误日志里找到:

  1. vi /opt/mysql57_data/mysql-error.log
  2. 2016-05-06T08:37:29.767232Z 1 [Note] A temporary password is generated for root@localhost: qXay8wk3RL*T

7. 设置client配置文件

vi ~/.my.cnf

  1. [client]
  2. user = root
  3. password = mysql
  4. port=3306
  5. socket = /opt/mysql57_data/mysql.sock

8. 测试一下无密码登录

  1. [root@node1 ~]# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 160
  4. Server version: 5.7.11-log MySQL Community Server (GPL)
  5. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
  10. mysql>

数据运维技术 » 一步一步教你如何在RHEL/CentOS上的安装MySQL 5.7