One of the recovery methods
1, first of all to confirm the security of the server state, that is, no one can arbitrarily connect 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, modify the MySQL login settings;
The code is as follows |
Copy Code |
Vim/etc/my.cnf |
In the paragraph of [mysqld], add: Skip-grant-tables saves and exits vim.
3. Reboot mysqld;
The code is as follows |
Copy Code |
Service mysqld Restart # or/etc/init.d/mysqld restart |
4, login and modify the MySQL root password;
The code is as follows |
Copy Code |
mysql> use MySQL; mysql> UPDATE user SET Password = Password (' New-password ') WHERE user = ' root '; mysql> flush Privileges; Mysql> quit Www.111cn.net |
5, the MySQL login settings to modify back;
The code is as follows |
Copy Code |
Vim/etc/my.cnf |
Delete the skip-grant-tables just added to the paragraph in [mysqld];
Save and exit Vim.
6, restart the mysqld;
The code is as follows |
Copy Code |
Service mysqld Restart # or/etc/init.d/mysqld restart |
7, restore the normal working state of the server;
Reverse the operation in step one. Restores the server's working status.
Two methods of recovery (recommended)
If you forget the MySQL root password, you can reset it in the following ways:
1, kill off the MySQL process in the system; Www.111cn.Net
The code is as follows |
Copy Code |
Killall-term mysqld |
2, use the following command to start MySQL, to do not check the right way to start;
The code is as follows |
Copy Code |
Safe_mysqld--skip-grant-tables & # Note: Press ENTER after execution |
3, and then use the null password method to log in with the root user MySQL;
The code is as follows |
Copy Code |
Mysql-u Root |
4, modify the root user password;
The code is as follows |
Copy Code |
mysql> Update Mysql.user Set Password=password (' New password ') where user= ' root '; mysql> flush Privileges; Mysql> quit; |
Restart MySQL and you can log on with the new 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;
The code is as follows |
Copy Code |
Service mysqld Stop # or/etc/init.d/mysqld stop |
(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 right way to start;
The code is as follows |
Copy Code |
Mysqld--skip-grant-tables & |
3, and then use the null password method to log in with the root user MySQL;
The code is as follows |
Copy Code |
Mysql-u Root |
4, modify the root user password;
The code is as follows |
Copy Code |
mysql> Update Mysql.user Set Password=password (' NewPassword ') where user= ' root '; mysql> flush Privileges; Mysql> quit;
|
Restart MySQL
The code is as follows |
Copy Code |
Servcie mysqld Restart # or/etc/init.d/mysql restart |
You can log on using the new password NewPassword.
Practice Experience:
Don't know what's going on when using the command
The code is as follows |
Copy Code |
Update Mysql.user set Password=password (' snsgou$123456 ') where user= ' root '; |
When the root secret is set to snsgou$123456, the password is always login failed!
When set to 123456 such a pure digital password, login success!
Subsequent solutions/tips:
First set the root password to a relatively simple pure number, such as 123456, and then through the phpMyAdmin tool to set the root password to a slightly more complex password! Done!
The SQL statement returned by phpMyAdmin is:
code is as follows |
copy code |
SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' ********* ') |