Reset Forgotten MySQL Root Password

Do you like HowtoForge? Please consider to support us by becoming a subscriber.
Submitted by cmdln (Contact Author) (Forums) on Tue, 2008-02-26 12:28. :: MySQL

Reset Forgotten MySQL Root Password 

Have you ever forgotten the root password on one of your MySQL servers? No? Well maybe I’m not as perfect as you. This is a quick h00tow (how to) reset your MySQL root password. It does require root access on your server. If you have forgotten that password wait for another article. Original article posted on reset mysql root password.

First things first. Log in as root and stop the mysql daemon. Now lets start up the mysql daemon and skip the grant tables which store the passwords.

mysqld_safe --skip-grant-tables

You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.

mysql --user=root mysql

update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;

Now kill your running mysqld, then restart it normally. You should be good to go. Try not to forget your password again.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Wed, 2009-02-11 14:35.
Submitted by Gee Thanks for ... (not registered) on Wed, 2009-02-11 06:32.

I did this this other day before I saw the comments.  My database is hosed.  Thankfully it was my small system but now I need to figure out how to fix it.  Thanks. 

 Next time please test this on your own server before posting! We appreciate the effort but can't afford this kind of help!

Submitted by Anonymous (not registered) on Mon, 2009-02-09 02:32.

Thank you for fucking up my entire database and all it's users!

.. someone either edit or delete this tutorial

Submitted by Anonymous (not registered) on Tue, 2008-12-16 22:07.
where user='root' must be added... Otherwise, it worked without a problem. thanx.
Submitted by Anonymous (not registered) on Mon, 2008-12-08 20:38.
This howto is wrong and dangerous! please add where user='root' at the end of the update statement!
Submitted by cnemo (not registered) on Tue, 2008-09-23 03:39.
Submitted by mahy (registered user) on Tue, 2008-04-15 06:50.

The following statement wil reset passwords for ALL USERS, not just root. This will do the desired thing:

UPDATE user SET Password=PASSWORD('newpwd') WHERE User='root';

Check out http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html for more advice.