1. First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily. Because the MySQL database is completely out of password-protected state during the reset of the root password of MySQL, other users can log in and modify the MySQL information arbitrarily. It is possible to implement the server's quasi-security state by enclosing 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. To modify the login settings for MySQL:
Add one sentence to the paragraph in [mysqld]: Skip-grant-tables Save and Exit VI.
3. Restart Mysqld
/etc/init.d/mysqld restart ( service mysqld restart )
4. Log in and modify the root password of MySQL
mysql> USE mysql ; mysql> UPDATE user SET Password = password ( ‘new-password‘ ) WHERE User = ‘root‘ ; mysql> flush privileges ; mysql> quit
5. 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.
6. Restart Mysqld
/etc/init.d/mysqld restart ( service mysqld restart )
7. Restore the server's normal working state
Reverse the action in step one. Restores the server's working status.
MySQL root password forgotten solution in Linux environment