Http://zhidao.baidu.com/question/39198255.html
Follow these steps to reset the MySQL Root Password:
1. First confirm that the server is in a secure state, that is, no one can connect to the MySQL database at will.
Because, during the resetting of the MySQL Root Password, the MySQL database is completely out of password-free
Other users can log on to and modify MySQL information as needed. You can use
The external port is closed, and Apache and all user processes are stopped to implement server quasi-security.
Status. The safest status is to operate on the server console and unplug the network cable.
2. Modify MySQL Logon Settings:
# Vi/etc/MySQL/My. CNF
Add the following sentence to the [mysqld] section: Skip-grant-tables
For example:
[Mysqld]
Datadir =/var/lib/MySQL
Socket =/var/lib/MySQL. Sock
Skip-name-resolve
Skip-grant-tables
Save and exit VI.
3. Restart mysqld
# Service MySQL restart
Stopping MYSQL: [OK]
Starting MYSQL: [OK]
4. log on to and modify the MySQL Root Password
#/Usr/bin/MySQL
Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 3 to server version: 3.23.56
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql> use MySQL;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed
Mysql> Update user SET Password = PASSWORD ('new-password') where user = 'root ';
Mysql> Update user SET Password = PASSWORD ('wtm98077') where user = 'root ';
Query OK, 0 rows affected (0.00 Sec)
Rows matched: 2 changed: 0 Warnings: 0
Mysql> flush privileges;
Query OK, 0 rows affected (0.01 Sec)
Mysql> quit
Bye
5. Modify the MySQL Logon Settings.
# Vi/etc/My. CNF
Delete the skip-grant-tables added to the [mysqld] section.
Save and exit VI.
6. Restart mysqld
#/Etc/init. d/mysqld restart
Stopping MYSQL: [OK]
Starting MYSQL: [OK]
The following lineCodeYou can change the password normally, but it takes effect only after the MySQL service is restarted.
Mysql> Update user SET Password = PASSWORD ('new-password') where user = 'root ';