1, installed in the centos6.5 mysql5.5.38 version, forget how to solve the password?
(1), first close the MYSQLD service
Service Mysqld Stop
(2), start with Mysqld_safe Safe Mode MySQL , use two parameters:
--skip-grant-tables: Skip Authorization Form
--skip-networking: Skip the network, prevent other users to read and write to the database, after the password recovery can open normally
Execute command:
Mysqld_safe--skip-grant-tables--skip-networking &
(3), no password login:
Mysql-u Root
(4), change the password:
mysql> use MySQL; # # #使用 mysql database
mysql> Update user set Password=password (' new password ') where user= ' Root '
mysql> flush Privileges;
Mysql> quit//Exit database
(5), restart the MySQL service
Service mysqld Restart
(6). Log in to MySQL with a new password
Mysql-uroot-p New Password
2, installed in the Centos7 mysql5.7.13 version of Forget Root password, how to solve?
(1), modify the main configuration file my.cnf
Vim/etc/my.cnf
# # #在 [Mysqld] added in
Skip-grant-tables
Save, exit
(2), restart MySQL service
Systemctl MySQL Restart
(3), use the root user login (password is empty, direct enter enter)
Mysql-u root-p
(4), execute the command in MySQL:
mysql> use MySQL;
mysql> Update user set Authentication_string=password (' new password ') where user=< /c5>'root';
Note: In the mysql5.7 version, there is no Password field, using authentication_string Field
mysql> flush Privileges;
Mysql> quit//Exit database
(5), add the original my.cnf configuration file Skip-grant-tables parameters, delete, restart service
sed-i ' s/skip-grant-tables//g/etc/my.cnf '
Systemctl Restart Mysqld
(6), log in to the database test with the new password:
Mysql-u root-p New Password
This article is from the "Keep Keep your" blog, be sure to keep this source http://keep88.blog.51cto.com/11829099/1909970
MySQL5.5.38 and MySQL5.7 versions forgot root password, workaround