One of the ways to restore MySQL passwords
1. First, verify that the server is in a secure state, that is, no one can arbitrarily connect to the MySQL database. Because the MySQL database is completely out of password protection during the reset of the MySQL root password, other users can also arbitrarily log in and modify MySQL information. The server's quasi-security status can be achieved by blocking 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 MySQL login settings:
In the paragraph of [mysqld], add a sentence: Skip-grant-tables Save and Exit VI.
3. Reboot mysqld
#/etc/init.d/mysqld Restart (Service mysqld restart)
4. Log in and modify the MySQL root password
mysql> use MySQL;
mysql> UPDATE user SET Password = Password (' New-password ') WHERE user = ' root ';
mysql> flush Privileges;
Mysql> quit
5. Change the MySQL login settings back
Delete the skip-grant-tables that you just added in the [mysqld] section
Save and Exit VI.
6. Reboot mysqld
#/etc/init.d/mysqld Restart (Service mysqld restart)
7. Restore the server's normal working status
Reverse the operation in step one. Restores the server's working status.
MySQL password recovery method bis
If you forget the MySQL root password, you can reset it in the following ways:
1. Kill off the MySQL process in the system;
2. Use the following command to start MySQL, to do not check the permissions of the way to start;
Safe_mysqld--skip-grant-tables &
3. Then use the null password method to log in to MySQL with root user;
4. Change the password of root user;
mysql> Update Mysql.user Set Password=password (' New password ') where user= ' root ';
mysql> flush Privileges;
Restart MySQL and you can log on with the new password
MySQL Password recovery method three
It is possible that your system does not have SAFE_MYSQLD programs (such as I now use the Ubuntu operating system, Apt-get installed MySQL), the following methods can be restored
1. Stop mysqld;
(You may have other methods, in short stop the mysqld run on it)
2. Use the following command to start MySQL, to do not check the permissions of the way to start;
Mysqld--skip-grant-tables &
3. Then use the null password method to log in to MySQL with root user;
4. Change the password of root user;
mysql> Update Mysql.user Set Password=password (' NewPassword ') where user= ' root ';
mysql> flush Privileges;
Restart MySQL
/etc/init.d/mysql restart
You can log on using the new password NewPassword.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.