CentOS system retrieves the MySQL database root login password

1. Modify the configuration file:

vi /etc/my.cnf 添加 skip-grant-tables 保存退出

PS:要在【MySQL】下面添加

Restart mysql:

centos7.x

systemctl restart mysqld

centos6.x

service mysqld restart

Password-free login:

mysql -u root

Enter the database:

use mysql

Modify the root password:

update user set authentication_string = password('新密码'),password_last_changed=now() where user='root';

Refresh permissions:

mysql>flush privileges;

Exit the mysql database:

quit

Modify the configuration file again:

vi /etc/my.cnf 删除 skip-grant-tables 保存退出

Restart the mysql service!!!

Guess you like

Origin blog.csdn.net/ichen820/article/details/114873274