MySQL - Password Recovery

If you've forgotten your root password, you'll need Linux Root login to reset your MySQL root password. Here is the steps for resetting forgotten MySQL root password.

First login to your Linux box as a root user, and stop the mysqld daemon.

service mysqld stop

Now, start the mysqld daemon without the grant table bypassing authentication.

mysqld_safe --skip-grant-tables &

The mysqld daemon should have started. Now login as a root user without the password.

mysql -u root
mysql> use mysql

Reset the root user password.

mysql> update user set Password=PASSWORD('new-password') where user='root';
mysql> flush privileges;
mysql> exit;

Restart the mysqld daemon, so that the new password will take into effect.

service mysqld restart

Other methods to recover the MySQL root password

/var/lib/mysql/mysql-pass-recover
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

Restart mysql with new init file

chown mysql:mysql /var/lib/mysql/mysql-pass-recover
/etc/rc.d/rc.mysqld stop
sleep 5
killall mysqld; killall mysqld; killall mysqld; killall mysqld;
sleep 5
mysqld_safe --init-file=/var/lib/mysql/mysql-pass-recover &
sleep 5
killall mysqld; killall mysqld; killall mysqld; killall mysqld;
sleep 5
/etc/rc.d/rc.mysqld start