Though it is rare case to change the root password of MySQL, but sometimes it happens the situation that you need to. You are helpless to recover the password and have to think about removing and re-installing it. But here are very few simple steps to reset the root password.
Steps
- First stop MySQL service.
sudo service mysql stop - Create MySQL service directory.
sudo mkdir /var/run/mysqld - Provide the MySQL user permission to write to the service directory.
sudo chown mysql: /var/run/mysqld - Start MySQL manually, without permission checks or networking.
sudo mysqld_safe –skip-grant-tables –skip-networking &
This will run in the background, you can ignore it or go to another tab for further steps. - Log in without a password.
mysql -uroot mysql - Update the password for the root user.
UPDATE mysql.user SET authentication_string=PASSWORD(”), plugin=’mysql_native_password’ WHERE User=’root’;
EXIT; - Turn off MySQL.
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown - Start the MySQL service normally.
sudo service mysql start - Login to MySQL with new password.
mysql -u root -p
Now you should be in with mysql prompt and continue using MySQL as usual.