Resetting MySQL root password

Forgot mysql root password? Follow the steps given below to reset it.

Step 1:

Stop the currently running mysql daemon.

sudo service mysql stop


 sudo /etc/init.d/mysql stop

Step 2:

Start mysql with --skip-grant-tables

sudo /usr/sbin/mysqld --skip-grant-tables &

Step 3:

Start the mysql client without a password

mysql -u root

Step 4:

From the client, flush privileges


Step 5:

Reset password by executing the following from mysql client

SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');

Step 6:

Reset password for all root, if remote connection is enabled, from mysql client

UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';

Step 7:

Run flush priveleges again, from the client


Step 8:

Exit the mysql client


Step 9:

Restart mysql

sudo service mysql stop
sudo service mysql start


sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Your password has been successfully reset. Now you may login  using your new password.