Follow the below steps to recover MySQL root password:
- Stop the MySQL server process
/etc/init.d/mysql stop
- Start the MySQL process with the –skip-grant-tables option so that it will not prompt for the password.
mysqld_safe --skip-grant-tables &
- Connect to the MySQL server as the root user:
mysql -u root
- Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-PASSWORD") where User='root';
flush privileges;
*Where NEW-PASSWORD is the new password to be used.
- Exit from mysql and stop the mysql service
mysql> quit
/etc/init.d/mysql stop
- Start mysql service
/etc/init.d/mysql start
- Login to the mysql root account with the new password
mysql -u root -p'NEW-PASSWORD'