Forgot login password for mysql5.7 under Centos

A small episode, I want to import the database before deploying the project. But reluctantly forgot the password (password policy is not turned off, the password is too long forgotten...)

vim /etc/my.cnf

Add a line of skip-grant-tables; save and exit
Add a row
and then execute again systemctl restart mysqld.service, restart the database

Directly at the back mysql -u root, log in without password, change the password

顺序执行
use mysql;
update user set authentication_string = password("newPassword") where user="root" ;
flush privileges;//刷新
quit;

Repeat the above vim /etc/my.cnfsteps again , delete and save the skip-grant-tables just now

Then perform systemctl restart mysqld.servicerestart the database
re- mysql -u root -plogin, just enter your password, you can log a discovery

If there are any errors, please raise them~ Thank you!

Guess you like

Origin blog.csdn.net/weixin_42553616/article/details/107608745