本人環境是centos7+mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
[root@wst-test02 bbders]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@wst-test02 bbders]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
官網下載地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
解壓
tar -xvf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
開始安裝
rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
#### 安裝mysql-community-server-5.7.20-1.el7.x86_64.rpm前需要安裝libaio-0.3.107-10.el6.x86_64.rpm
下載地址:http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm(若在有網情況下可執行yum install libaio)
安裝成功後,也可把安裝文件和臨時文件刪除。
rm mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
// 初始化,執行生會在/var/log/mysqld.log生成隨機密碼
[root@wst-test02 bbders]# mysqld --initialize
[root@wst-test02 bbders]# groupadd mysql
[root@wst-test02 bbders]# useradd -g mysql -r mysql
[root@wst-test02 bbders]# chown mysql:mysql /var/lib/mysql -R
// 將mysql安裝目錄賦給mysql
[root@wst-test02 bbders]# systemctl start mysqld.service
// 重啓mysql
由於一開始並不知道密碼,先修改配置文件/etc/my.cnf令MySQL跳過登錄時的權限檢驗。加入一行:skip-grant-tables
重啓MySQL: systemctl restart mysqld
免密碼登錄MySQL: mysql -uroot -p
## 連續敲兩下'回車鍵'
修改root用戶密碼: UPDATE user SET authentication_string = password('your-password') WHERE host = 'localhost' AND user = 'root';
最後修改配置文件/etc/my.cnf刪除此前新增那一行skip-grant-tables,並重啓MySQL。這一步非常重要,不執行可能導致嚴重的安全問題。
提示1130錯誤
總體運行語句:
mysql -u root -p
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select 'host' from user where user='root';