How to recover MySQL root password
If you are unable to recall the password for MySQL root account you will need to reset it. Remember that by default MySQL root account has an empty password so try that first.
- Login as root to the machine with the MySQL server (not to MySQL).
- Stop the MySQL server by using either of the following command:
$ /etc/init.d/mysql stop
- Now the MySQL server must be started so that it does not take user credentials into account:
mysqld_safe --skip-grant-tables &
- Once MySQL has been started in this manner you (and anyone else who has access to this machine so be aware of inherent danger here!) can simply connect as root user without password:
$ mysql -u root
- Now simply change the root password and force MySQL server to take it into account:
mysql> use mysql;
mysql> update user set password=PASSWORD(Ã¢â‚¬Å“rootPassOfYoutChoiceÃ¢â‚¬Â) where user=Ã¢â‚¬â„¢rootÃ¢â‚¬â„¢;
mysql> flush privileges;
- Once root password is changed we need to restart MySQL server because right now it is not taking user credentials into account:
$ /etc/init.d/mysql restart
After this point MySQL server will operate just as before with the root account having the new password.