Recover MySQL root password

Ever tried losing your MySQL root password, because you’re an idiot or a coworker changed it without documenting or telling?

Well, within 10 minutes this can be fixed. This guide applies to Debian and probably others too. su – to root and perform the following.

1. Stop MySQL

/etc/init.d/mysql stop

2. Start MySQL and skip grant tables, put it to background so you can work

mysqld_safe –skip-grant-tables &

3. Enter MySQL as root

mysql -u root

4. Change the password within the MySQL console

mysql> use mysql;
mysql> update user set password=PASSWORD(“insert-new-password-here”) where User=’root’;
mysql> flush privileges;
mysql> quit

5. Stop MySQL server again

/etc/init.d/mysql stop

– Now if that did not work, find the MySQL process with ps and kill it.

6. Start MySQL again

/etc/init.d/mysql start

And it should work.. test it by typing “mysql -u root -p” and enter the password you just created.

This entry was posted in Random. Bookmark the permalink. Both comments and trackbacks are currently closed.