since 1999

 

1 minutes estimated reading time.

Reset MySQL Root Password with One Command

Locked Out, Again

I have locked myself out of important accounts more than a few times. Just this morning, I found myself again locked out of a MySQL database server on an Ubuntu Linux machine. Though this should work with any Debian-based Linux that uses the apt-get package management system.

Fortunately, I had administrative access to the server through SSH and thus was able to reset the MySQL root password with the package management script. It only took one, simple command.

sudo dpkg-reconfigure mysql-server-5.5

After entering my system password for sudo, I was prompted for the password I wanted to use for MySQL. The server then stopped and started back up again and I was able to login with the new root password.

This is the easy way to do this. Googling will turn up solutions that involve stopping mysql and skipping grant tables. I prefer to use this method instead.

Though, if you want to see more behind the scenes, see: