Recover the MySQL Root Password in Linux

Step 1 – At the linux shell, stop the current mysqld process, start the mysqld_safe process with –skip-grant-tables switch and login as root (no password).

/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root

Step 2 – At the mysql shell set the root password and flush privileges.

USE mysql;
UPDATE user SET password=PASSWORD("new-password-here") WHERE User='root';
FLUSH PRIVILEGES;
QUIT;

Step 3 – Back at the linux shell stop the mysqld_safe process and start the normal mysqld process. At this point you should be able to successfully login as root using the password from Step 2.

/etc/init.d/mysql stop
/etc/init.d/mysql start
mysql -u root -p

Leave a Reply