You can recover MySQL root password if you don’t remember the old password OR if it isn’t working. Performing 5 steps with the commands as it is, will reset the MySQL root password for you.
1. Stop the MySQL service.
2. Start the MySQL service in safe mode. Doing this, it won’t ask you for password.
3. Access MySQL as root user.
4. Set a new password for MySQL root user.
5. Restart MySQL service.
Above are the steps. If you are unsure with the commands, kindly follow them as below.
1. Stop the MySQL service.
# /etc/init.d/mysql stop
2. Start the MySQL service in safe mode. Doing this, it won’t ask you for password.
# mysqld_safe –skip-grant-tables &
3. Access MySQL as root user.
# mysql -u root
4. Set a new password for MySQL root user.
mysql> use mysql;
mysql> update user set password=PASSWORD(“New-Password”) where User=’root’;
mysql> flush privileges;
mysql> quit
5. Restart MySQL service.
# /etc/init.d/mysql stop
Now try connecting MySQL with the new root password. You should be able to get into the MySQL prompt.
Note: Replace New-Password in Step 4 with the actual password you wish to set.