1. Open
/etc/my.cnf
Add a sentence to the paragraph in [mysqld]: Skip-grant-tables
For example:
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Skip-grant-tables
...
2. Restart MySQL
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]
3. Log in and modify the root password of MySQL
Input/usr/bin/mysql
Appear:
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.
input Use MySQL;
Appear:
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a
Database changed
Input:
UPDATE user SET Password = Password (' 123456 ') WHERE user = ' root '; Change the password here to 123456;
Appear:
Query OK, 0 rows Affected (0.00 sec)
Rows matched:2 changed:0 warnings:0
Input: Flush privileges;
Query OK, 0 rows affected (0.01 sec)
Input: Quit
Bye
4. Change MySQL login settings back
# VI/ETC/MY.CNF
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and Exit VI.
5. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]
Linux Reset mysql Password