one of the ways to recover MySQL passwords1. 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 MySQL login settings: # VI/etc/my.cnf in[mysqld]Add one sentence to the paragraph: Skip-Grant-tables Save and Exit VI. 3. Restart Mysqld #/etc/Init.d/mysqld Restart (service mysqld restart)4. Log in and modify the root password for MySQL MySQL> UseMySQL ; MySQL> UPDATE User SETPassword=Password ('New-password')WHERE User = 'Root'; MySQL>FlushPrivileges; MySQL>quit5. Change MySQL login settings back to # VI/etc/MY.CNF would have just[mysqld]In the paragraph, add the Skip-Grant-Tables Delete Save and Exit VI. 6. Restart Mysqld #/etc/Init.d/mysqld Restart (service mysqld restart)7. Restoring the server's normal working state reverses the operation in step one. Restores the server's working status. MySQL Password recovery method Two If you forget the root password of MySQL, you can reset it in the following ways:1. Kill the MySQL process in the system; Killall-Term mysqld2start MySQL with the following command to start without checking permissions; Safe_mysqld--Skip-grant-tables &3. Then log in to MySQL using the root user with a blank password; MySQL-u root4. Modify the root user's password; MySQL> UpdateMysql.User SetPassword=PASSWORD ('New Password')where User='Root'; MySQL>FlushPrivileges; MySQL>quit restart MySQL, you can use the new password to log in to the MySQL password recovery method Three possible your system does not have SAFE_MYSQLD program (for example, I am using the Ubuntu operating system, APT-get installed MySQL), the following method can be restored1. Stop mysqld;/etc/Init.d/MySQL Stop (you may have other ways to stop mysqld running anyway)2start MySQL with the following command to start without checking permissions; Mysqld--Skip-grant-tables &3. Then log in to MySQL using the root user with a blank password; MySQL-u root4. Modify the root user's password; MySQL> UpdateMysql.User SetPassword=PASSWORD ('NewPassword')where User='Root'; MySQL>FlushPrivileges; MySQL>quit restart MySQL/etc/Init.d/MySQL restart can log in with the new password newpassword.
MySQL root password forgotten solution in Linux environment