One of the ways to recover MySQL passwords
1. First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily. Because the MySQL database is completely out of password-protected state during the reset of the root password of MySQL, other users can log in and modify the MySQL information arbitrarily. It is possible to implement the server's quasi-security state by enclosing MySQL's external ports and stopping Apache and all user processes. The safest state is to operate on the console of the server and unplug the network cable.
2. To modify the login settings for MySQL:
?
Add one sentence to the paragraph in [mysqld]: Skip-grant-tables Save and Exit VI.
3. Restart Mysqld
?
1 |
# /etc/init.d/mysqld restart ( service mysqld restart ) |
4. Log in and modify the root password of MySQL
?
1234 |
mysql> USE mysql ; mysql> UPDATE user SET Password = password ( ‘new-password‘ ) WHERE User = ‘root‘ ; mysql> flush privileges ; mysql> quit |
5. Change MySQL login settings back
?
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and Exit VI.
6. Restart Mysqld
?
1 |
# /etc/init.d/mysqld restart ( service mysqld restart ) |
7. Restore the server's normal working state
Reverse the action in step one. Restores the server's working status.
MySQL password recovery method of the second
If you forget the root password for MySQL, you can reset it in the following ways:
1. Kill the MySQL process in the system;
?
2. Start MySQL with the following command to start without checking permissions;
?
1 |
safe_mysqld --skip-grant-tables & |
3. Then log in to MySQL using the root user with a blank password;
?
4. Change the password of the root user;
?
123 |
mysql> update mysql. user set password = PASSWORD ( ‘新密码‘ ) where User = ‘root‘ ; mysql> flush privileges ; mysql> quit |
Restart MySQL and you can log in with the new password
MySQL Password recovery method III (recommended)
It is possible that your system does not have a SAFE_MYSQLD program (such as the Ubuntu OS I am using now, Apt-get installed MySQL), the following method can be restored
1. Stop mysqld;
?
(You may have other ways to stop mysqld running anyway)
2. Start MySQL with the following command to start without checking permissions;
?
1 |
mysqld --skip-grant-tables & |
3. Then log in to MySQL using the root user with a blank password;
?
4. Change the password of the root user;
?
123 |
mysql> update mysql. user set password = PASSWORD ( ‘newpassword‘ ) where User = ‘root‘ ; mysql> flush privileges ; mysql> quit |
Restart MySQL
?
1 |
/etc/init .d /mysql restart |
You can log in with the new password newpassword.
MySQL root password forgotten solution in Linux environment (three kinds)-recommend the third Kind