Reset the root password on MySQL
Posted by jharr on January 4th, 2008
Email This Post
Yes, it really is this easy.run the following command to change the mysql root password
sudo /etc/init.d/mysql reset-password
New MySQL root password:
Verify:
Setting new MySQL root password
But how? Debian (and by inheritance, Ubuntu) have a special user called ‘debian-sys-maint’ on each mysql install that has admin privileges on the server. It’s used to shutdown the server gracefully, automatically check for corrupt tables, and resetting your password. Its password is randomly generated, and stored in /etc/mysql/debian.cnf. Handy if you want to do some admin scripts yourself.
If you want to be notified the next time we write something please subscribe to our RSS feed.Thanks for Visiting!


July 7th, 2008 at 6:33 pm
I can reset my password. ‘reset-password’ command is not on my debian-etch. it says me:
Usage: /etc/init.d/mysql start|stop|restart|reload|force-reload|status
July 9th, 2008 at 11:38 pm
Same here… did you ever find an answer to why the ‘reset-password’ does not work?
July 10th, 2008 at 6:14 am
try the following procedure
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-tablesYou 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 mysqlupdate user set Password=PASSWORD(’new-password’);
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.
July 16th, 2008 at 7:52 pm
The above advice will change ALL of the mysql users’ passwords! You only want to change the password for the user named ‘root’, so add that constraint:
update user set Password=PASSWORD(’new-password’) WHERE User=’root’;