1. First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily. Because the database is MySQL root completely out of password-protected state during the reset password, MySQL other users can log in and modify MySQL the information arbitrarily. The server's quasi-secure state can be implemented using a method that closes the MySQL external ports and stops Apache and all user processes. The safest state is to operate on top of the server Console and unplug the network cable.
2. Modify MySQL the logon settings:
# vi /etc/my.cnf
In [mysqld] the paragraph, add one sentence: skip-grant-tables
For example:
[mysqld] datadir=/var/lib/mysql socket=/var/libskip
3. Restartmysqld
# /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK
4. Login and modify MySQL the root password
#/usr/bin/mysqlWelcome to theMySQL Monitor. Commands End with; or \g. Your MySQL Connection ID is3 toServerversion:3.23. theType' help; ' or ' \h ' forHelp. Type' \c ' to Clear theBuffer. mysql> use MySQL; Reading table Information forCompletion ofTable andColumn names can turn off this feature to Get aQuicker startup with-A Database changed mysql> UPDATE user SET Password = Password (' New-password ') WHERE User =' Root '; Query OK,0Rows Affected (0.00 sec) Rows matched:2Changed:0Warnings:0mysql> flush Privileges; Query OK,0Rows Affected (0.01 sec) Mysql> quit Bye
5. MySQLChange the login settings back
# vi /etc/my.cnf
Add the deletion that you just [mysqld] added in the paragraph skip-grant-tables
6. Restartmysqld
# /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]
Work for fun,live for love!
MySQL root password forgotten solution under Linux