How to Reset a Forgotten MySQL Root Password

I had the luck to forget the root MySQL password on one of my servers today (a VPS with CentOS 6.2). So I had no choice but to reset the root password. Just in case you get in the same boat with me, here’s what I did. First off, stop the MySQL server.

service mysqld stop

Then start the mysql daemon skipping the grants table which stores the password.

mysqld_safe --skip-grant-tables

This will start the mysql daemon but will not exit. You’ll need to connect again to the server on another terminal. This time you can login as root without the password.

mysql --user=root mysql

Then this command will reset the root password.

update user set password=PASSWORD('new-password') where user='root';

Flush privileges and you are done.

flush privileges;

Do take note that resetting the root password has its inherent risks. So make sure you understand what you are doing before you execute a command. Take note that I was running as (linux) root to execute the reset.

You might also like More from author