I recently forgot the root password to a MySQL instance on one of my machines.
Follow this quick and easy guide for whenever this happens to you.
Stop MySQL
sudo service mysql stop
Start MySQL Safe Mode
sudo mysqld_safe –skip-grant-tables &
Login as Root (with no password)
mysql -uroot
Switch to the MySQL db, reset root’s password, flush and logout
USE mysql;
UPDATE user SET password=PASSWORD(“mynewpassword”) WHERE user=’root’;
FLUSH PRIVILEGES;
QUIT
Stop MySQL Safe Mode
sudo service mysql stop
Start MySQL normally
sudo service mysql start
And that’s it!
… And you’re done! Your root password is now whatever you set it to!
Note: Depending on your distribution, mysql start/stop commands may differ. However MySQL Safe Mode should be the same on any distribution.