The perfect solution for Mysql forgot root password

1. Change the my.cnf configuration file

1. Edit the /etc/my.cnf configuration file with the command, namely: vim /etc/my.cnf or vi /etc/my.cnf

2. Add skip-grant-tables under [mysqld], then save and exit

3. Restart the mysql service: service mysqld restart

Second, change the root user name

1. After restarting, execute the mysql command to enter the mysql command line

2. Modify the root user password

?

1

2

3

MySQL> UPDATE mysql.user SET Password=PASSWORD('新密码') where USER='root';

MySQL> flush privileges;

MySQL> exit

3. Comment out the skip-grant-tables in /etc/my.cnf, and then restart mysql, namely: service mysqld restart

Well, now you can log in with the new root password!

The above is the Mysql forgot root password handling method introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message to me, and the editor will reply to you in time. Thank you very much for your support to the Scripting House website!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325578416&siteId=291194637