1. First verify that the server is in a secure state,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:
# vim/etc/my.cnf
Add one sentence to the paragraph in [mysqld]: Skip-grant-tables For example:
[mysqld]
skip-grant-tables
Save and exit Vim. 3. Restart Mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4. Log in and modify the root password of MySQL
# /usr/bin/mysql
mysql> use mysql ;
mysql> update user set password=password(‘new-password‘) where User=‘root‘;
mysql> flush privileges ;
mysql> \q
Bye
5. Change MySQL login settings back
# vim/etc/my.cnf
Delete the skip-grant-tables you just added in the paragraph [mysqld]Save and exit Vim. 6. Restart Mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
From for notes (Wiz)
MySQL root password forgotten solution under Linux