Rietta
Rietta.com Security
You are reading The Rietta Blog, a publication about the web since 2005.

Reset MySQL Root Password With One Command

Comments

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.

1
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:

About Frank Rietta

Frank Rietta's photo

Frank Rietta is a web application security consultant, software developer, author, and speaker. He is a computer scientist with a Masters in Information Security from the College of Computing at the Georgia Institute of Technology. He teaches about security topics and is a contributor to the security chapter of the 7th edition of the "Fundamentals of Database Systems" textbook published by Addison-Wesley.

Comments