Solution of forgetting MySQL root password

Time:2022-5-9

I MySQL password recoverymethodone of
If you forget the root password of MySQL, you can use the followingmethodagainset up
1. KillsystemMySQL process in;
killall -TERM mysqld
2. Start MySQL with the following command and start it without checking permissions;
safe_mysqld –skip-grant-tables &
3. Then log in to MySQL by using the root user with an empty password;
mysql -u root
4. Modify the password of root user;
mysql> update mysql. User set password = password (‘New password ‘) where user =’root’;
mysql> flush privileges;
mysql> quit
Restart MySQL and you can log in with the new password.

II MySQL password recoverymethodtwo
It’s possible that yousystemNo safe_ Mysqld program (such as the Ubuntu operation I use now)system, MySQL installed by apt get), belowmethodCan recover
1. Stop mysqld;  
   /etc/init.d/mysql stop
(you may have othermethodIn short, just stop mysqld)

2. Start MySQL with the following command and start it without checking permissions;  
mysqld –skip-grant-tables &
3. Then log in to MySQL by using the root user with an empty password;
mysql -u root
4. Modify the password of root user;
mysql> update mysql.user set password=PASSWORD(‘newpassword’) where User=’root’;
mysql> flush privileges;
mysql> quit
Restart MySQL
/etc/init.d/mysql restart
You can log in with the new password.