Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Last Updated: Mar 27, 2024

Reset MySQL Root Password

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM


If you've ever lost or forgotten your MySQL root password, you know how frustrating that can be. Fortunately, MySQL provides a straightforward method to reset it. 

Reset mysql root password

This article will walk you through the process of resetting your MySQL root password, ensuring you regain access to your databases.

Understanding MySQL Root Password

What is the MySQL Root Password?

In MySQL, the 'root' is the username of the superuser account, which has full access to all databases on the server. The root password is the key to this account.

Why is the Root Password Important?

The root password is crucial as it:

Controls Access: It prevents unauthorized users from accessing your databases.

Manages Permissions: It allows the assignment of specific permissions to other users.

Resetting the MySQL Root Password

The process varies slightly depending on the operating system you're using. For this guide, we'll cover the procedure for a Linux/Unix system.

Step 1: Stop the MySQL Service

First, you need to stop the running MySQL service. You can do this using the following command in your terminal:

sudo service mysql stop

Step 2: Start MySQL Without Password Verification

Next, start MySQL in safe mode without password validation:

sudo mysqld_safe --skip-grant-tables &

Step 3: Access MySQL and Change the Root Password

Now, access MySQL as root:

mysql -u root

You'll enter the MySQL interface. Now, reset the root password:

USE mysql;
UPDATE user SET authentication_string=PASSWORD('new_password') WHERE User='root';
Replace 'new_password' with your new root password.

Step 4: Restart the MySQL Service

Finally, exit the MySQL interface by typing exit and restart the MySQL service:

sudo service mysql restart

You have now successfully reset your MySQL root password!

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Frequently Asked Questions

Can I use this method to change the password of other MySQL users?

Yes, just replace 'root' with the username in the UPDATE statement.

I am on Windows. Can I follow these steps?

While the process is similar, commands may vary on Windows. Use the MySQL documentation for Windows-specific instructions.

What if I forget the new password again?

Just follow these steps again to reset your password.


Forgetting your MySQL root password can be a hassle, but as we've seen, it's not an insurmountable problem. With a few simple steps, you can regain access to your MySQL server. Just remember to keep your password safe and secure. If you do forget it, don't panic - you now have the tools to get back on track. And always ensure you follow best security practices when dealing with database credentials.

Here are some more related articles:

You may refer to our Guided Path on Code Studios for enhancing your skill set on DSA, Competitive Programming, System Design, etc. Check out essential interview questions, practice our available mock tests, look at the interview bundle for interview preparations, and so much more!

Happy Learning!!

Topics covered
Understanding MySQL Root Password
Why is the Root Password Important?
Frequently Asked Questions
Can I use this method to change the password of other MySQL users?
I am on Windows. Can I follow these steps?
What if I forget the new password again?