Let’s learn how to recover MySQL root password in case you have lost it. Know how to recover MySQL root password.
You must login to your account using SSH as the root user to recover MySQL root password.
Use following command for CentOS and Fedora:
service mysqld stop
Use following command for Debian and Ubuntu:
service mysql stop
Use following command with the —skip-grant-tables option, to restart the MySQL server.
mysqld_safe --skip-grant-tables &
Log into MySQL using the following command
At the mysql> prompt, to reset the password type the following command, replacing NEW-PASSWORD with the new root password
UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root';
At the mysql> prompt, type the following commands:
FLUSH PRIVILEGES; exit;
Stop the MySQL server using the following command. You will be prompted to enter the new MySQL root password before the MySQL server shuts down:
mysqladmin -u root -p shutdown
Start the MySQL server normally, type the appropriate command for your Linux distribution:
For Debian and Ubuntu:
service mysql start
For CentOS and Fedora:
service mysqld start