Recover Reset MySql Root Password

It has been a few weeks since I last touched the server and I couldn’t remember the root password for MySql. I’m lucky enough to find the following website, which tells me how to get around it.

The whole idea is very clever, all we need to do is to stop MySql process and start it without the permission mode. Then we can choose to reset the password and restart the MySql again.

$ sudo /etc/init.d/mysql stop

$ sudo mysqld_safe –skip-grant-tables &

$ mysql -u root

Now that we are in …

> use mysql

> UPDATE user SET password = PASSWORD(‘NEW-PASSWORD’) WHERE user = ‘root’;

> flush privileges;

> quit

Then re can restart the MySql and try to login with the new password.

$ sudo /etc/init.d/mysql restart

# mysql -u root -p