1. Modify the MySQL login settings:
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
Save and exit
2, restart Mysqld
# service Mysqld Restart stopping MySQL: [OK] starting MySQL: [OK]
3. Log in and modify the root password of MySQL
# mysql Welcome toThe MySQL Monitor. CommandsEnd with;or\g. Your MySQL Connection ID is 3 toServer version:3.23. AboutType'Help ;' or '\h' forHelp. Type'\c' toclear the buffer. mysql> UseMySQL;Databasechanged MySQL> UPDATE User SETPassword=Password ('New-password')WHERE User = 'Root' ; Query OK,0Rows Affected (0.00sec) Rows matched:2Changed:0Warnings:0MySQL>FlushPrivileges ; Query OK,0Rows Affected (0.01sec) MySQL>Quit
4. Change the MySQL login settings back
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and exit
5, restart Mysqld
# service Mysqld Restart stopping MySQL: [OK] starting MySQL: [OK]
MySQL forgot password