一步一步教你如何在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
- cd mysql5.7
- rpm -ihv *.rpm –nodeps
注:我的环境不干净,装了多套MySQL。正常应该把上面的”–nodeps”去掉,或者用”yum install *.rpm”安装。
如果由于和已安装的mysql冲突失败,卸载冲突的旧版mysql再执行,比如:
- rpm -e mysql-libs-5.1.61 –nodeps
- rpm -e mysql-5.1.61 –nodeps
3. 根据环境修改配置文件
- vi /etc/my.cnf
4. 初始化数据库
- mysqld –initialize –user mysql
5. 启动数据库
- mysqld_safe &
6. 连接数据库并修改密码
- mysql -S /opt/mysql57_data/mysql.sock -uroot -pqXay8wk3RL*T -e “ALTER USER USER() IDENTIFIED BY ‘mysql'”
上面假设数据目录为”/opt/mysql57_data”,初始密码”qXay8wk3RL*T”,这两项需要根据实际情况修改。
初始密码可以在错误日志里找到:
- vi /opt/mysql57_data/mysql-error.log
- …
- 2016-05-06T08:37:29.767232Z 1 [Note] A temporary password is generated for root@localhost: qXay8wk3RL*T
7. 设置client配置文件
vi ~/.my.cnf
- [client]
- user = root
- password = mysql
- port=3306
- socket = /opt/mysql57_data/mysql.sock
8. 测试一下无密码登录
- [root@node1 ~]# mysql
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 160
- Server version: 5.7.11-log 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>