You can recover MySQL root user password with following steps:
- Login to your linux machine as a root user
- Stop MySQL by executing the following command:
# service mysqld stop - Now, Start MySQL with --skip-grant-tables option. This command will skip the prompt for password.
# mysqld_safe --skip-grant-tables & - Login to MySQL server as a root user.
# mysql -u root - Now, you can set the new MySQL root password by executing following commands.
mysql> use mysql;
mysql> update user set password=PASSWORD("PASSWORD") where user='root';
mysql> flush privileges;
mysql> quit - Exit from MySQL and restart MySQL process.
# service mysqld stop - Start MySQL normally and test the new root user password.
# service mysqld start
# mysql -u root -p