Change or Reset the MySQL Root password via Command Line

In some cases, you could forget MySQL Root password then you can get it back by using command line as following.

Here are 5 easy steps to reset your MySQL Root password on VPS or dedicated server.

1. Turn off MySQL server:
service mysql stop

If the command above didn't work or turn off Mysql service then you can use this
killall mysql

2. Turn on MySQL at safe mode
mysqld_safe --skip-grant-tables

3. Change root password of MySQL
mysql -u root -p

mysql> USE mysql;
mysql> UPDATE user SET password = PASSWORD("new_password") WHERE User = 'root';

You change new_password with your new password

4. Turn off safe mode of MySQL
killall mysqld_safe

5. Turn on MySQL at normal mode
sudo service mysql start

Ok, now you changed Mysql root password and using it for next times.

Good luck!
 
Top