mySQL: How to reset root password

If the password for the mysql “root” user is lost, it’s still possible reset it to some other value.
The restart of the mySQL server will be necessary, of course.

The following should be done:

Stop the server
It could be done normally:

/etc/init.d/mysql stop

or effectively:

ps -ef | grep mysql
...
mysql 25079 1 0 Jan 31 ? 0:00 /usr/bin/mysqld
...
kill -9 25079

Please ensure that the proper process is killed!

Start MySQL server without security checking

mysqld_safe --skip-grant-tables &

Connect to mySQL without password

mysql -u root

Reset mySQL root password

use mysql;
update user set password=PASSWORD("NEW_PASSWORD") where user='root';
flush privileges;

Use the real new password instead of the string “NEW_PASSWORD”.

Restart mySQL server

/etc/init.d/mysql stop
/etc/init.d/mysql start

Check the connection

mysql -u root -p

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.