After MySQL 5.7 is installed in rpm mode in CentOS 7, root login cannot be used.
Recently, the latest mysql-server 5.7 (mysql57-community-release-el7-7.noarch.rpm) version was installed in CentOS 7 using rpm, and root login was not available after installation was successful. Baidu and google failed to find the answer in the official document. Now we have recorded the complete installation and troubleshooting process, hoping to help other friends.
Install MySQL5.6 In the RPM package of CentOS6.5
Install MySQL 5.6.21 in CentOS 6.5
MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF
OS version:
Linux version 3.10.0-327. el7.x86 _ 64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) #1 SMP Thu Nov 19 22:10:57 UTC 2015
The procedure for installing mysql-server in RPM mode is as follows:
$ Su root
$ Sudo wget http://repo.mysql.com/mysql57-community-release-el7-7.noarch.rpm
$ Sudo rpm-ivh mysql57-community-release-el7-7.noarch.rpm
$ Sudo yum install mysql-server
# Prompt for successful installation after yes
So far, mysql57 has been successfully installed. Now try to log on to mysql using root, and the ERROR code "ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' is displayed'
This problem occurs because mysql uses the default password to initialize the root user after the rpm installation.
The solution obtained by Du Niang Google is invalid for version 5.7.x. On the official website to find some ideas https://dev.mysql.com/doc/refman/5.7/en/server-management-using-systemd.html
MySQL 5.7.x has some new changes, which are roughly
1. mysqld_safe has been deprecated. By default, mysqld_safe is not installed in the rpm installation package.
2. The password column in the user table has been changed to authentication_string
After multiple tests, the root login problem was finally solved. The solution is as follows:
$ Sudo systemctl stop mysqld. service
$ Sudo systemctl set-environment MYSQLD_OPTS = "-- user = mysql -- skip-grant-tables -- skip-networking"
$ Sudo systemctl start mysqld. service
$ Mysql-u root mysql
Mysql> UPDATE mysql. user SET authentication_string = PASSWORD ("abcdef") WHERE user = 'root' and host = 'localhost ';
Mysql> flush privileges;
Mysql> quit
$ Sudo systemctl unset-environment MYSQLD_OPTS
$ Sudo systemctl restart mysqld. service
OK. After performing the preceding steps, you can use the root account to log on again.