How to reset MySQL root password?

If you forgot root password for your MySQL database server, there is still a way to access your database and even reset your password using the command prompt. For both Linux and Windows, you may kindly refer below steps that I would like to share for today. Hope this guideline help a lot of you out there.

Windows

1. Stop your MySQL server completely. You can go to services and stop the service there.
2. Open command prompt or CMD, then go to your MySQL bin folder, such as C:\MySQL\bin  
3. Execute the following command in the command prompt:
mysqld.exe -u root –skip-grant-tables  
4. Leave the current command prompt as it is, and open a new command prompt window.
5. Go to your MySQL bin folder again.
6. Enter “mysql” and press enter.  
7. You should now have the MySQL command prompt working. Type 
“use mysql;” 
so that we switch to the “mysql” database.
8. Execute the following command to update the password:
UPDATE user SET Password = PASSWORD(‘your_new_passowrd’) WHERE User = ‘root’;
* ensure to change your_new_password with your own password  
9.  After you are finished close the first command prompt, and type “exit;” in the second command prompt windows. 10. Start the MySQL service

Linux

1. Stop the MySQL server process by run below command  
# /etc/init.d/mysql stop OR service msyqld stop  
2. Start the MySQL (mysqld) server process without the password  
# mysqld_safe –skip-grant-tables &  
3. Connect to mysql server as the root user  
# mysql -u root  
4. Setup new mysql root account password or reset mysql password  
mysql> use mysql;
mysql> update user set password=PASSWORD(“NEW-ROOT-PASSWORD”) where User=’root’;
mysql> flush privileges;
* ensure update NEW-ROOT_PASSWORD with your own password
5. Exit the MySQL server.  
mysql> quit  
6. Start the MySQL server
# /etc/init.d/mysql start OR service mysqld start
7. You may test the new password by run below command  
# mysql -u root -p



Comments