Operating system is CENTOS7 64
1, modify the/ETC/MY.CNF, add a line under the [mysqld] subsection: Skip-grant-tables=1
This line of configuration allows mysqld to be not validated at startup
2. Restart MYSQLD service: systemctl restart Mysqld
3. Log in to Mysql:mysql-u root using the root user
4. Switch to MySQL database and update user table:
Update user Set authentication_string = password (' root '), password_expired = ' N ', password_last_changed = Now () where user = ' root ';
In previous versions, the field name for the password field was password,5.7 to authentication_string
5. Quit MySQL, edit the/etc/my.cnf file, delete the contents of Skip-grant-tables=1
6, restart the Mysqld service, and then login with the new password can
In addition, MySQL 5.7 generates a random initial password after initial installation (CentOS7 OS) and is recorded in the/var/log/mysqld.log, which can be viewed through the cat command, looking for the password keyword
After locating the password, log in with the initial password, and (only) change the root user's password to root by alter user ' root ' @ ' localhost ' identified by ' root ', then exit, Log in again with the root user and the password you just set.
mysql5.7 series Change root default password