How To Reset MySQL Password

on Tuesday, May 15, 2012
Sometimes, people forgot their password of MySQL. Then they confuse how to get back the root account on the MySQL Server. In this tutorial, we will show you step by step how to reset MySQL password.

First, you need to stop the MySQL service. Follow this command to stop the MySQL Service.
sudo service mysql stop
Next step is, you must start MySQL service again but with --skip-grant-tables option.
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

Because you are not checking the privileges when start the MySQL Service. It is better for you to stop the Networking to prevent the security less action.

The next, login to the MySQL server using root account.
mysql -u root
After login with root account without password, please flush the privileges using this command
FLUSH PRIVILEGES;
Then, update your password
SET PASSWORD FOR root@'localhost' = PASSWORD('your password');
Then FLUSH PRIVILEGES again. Now, your password has been changed. Do not forget to restart your MySQL Service, with this command:
sudo service mysql restart
To summarize the action are:
sudo server mysql stop
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
FLUSH PRIVILEGES;
SET PASSWORD FOR root@'localhost' = PASSWORD('your password');
FLUSH PRIVILEGES;

0 comments:

Post a Comment