Recover MySQL root password

If you ever loose your mysql root password (remember is not the same as the system root password) you can recover it following this steps:

Stop MySQL service either by:

#/etc/init.d/mysqld stop

or:

kill `cat /var/run/mysqld/mysqld.pid`
Start MySQL in safe mode
mysqld_safe --skip-grant-tables
Enter the console as root
mysql -u root
Set the new password
mysql> UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
Update the privileges
mysql> FLUSH PRIVILEGES;

You may also like