The fastest way to reset a MySQL password depends on your operating system
If you have forgotten the MySQL root password or lost access to an account, you can reset it without knowing the current password. The method differs between Windows and Linux, but both involve stopping the MySQL service, restarting it in a special mode that skips authentication, and then setting a new password. On most systems, this takes 10 to 15 minutes.
The reason this works is that MySQL can start without loading its permission tables, which means no password check happens at login. Once you are in, you can change any password you need. After that, you restart MySQL normally and log in with the new password.
Key Takeaways
- On Linux, stop MySQL, start it with the --skip-grant-tables flag, connect without a password, and run an UPDATE statement to set a new password.
- On Windows, stop the MySQL service, restart it from the command line with --skip-grant-tables, then follow the same password update steps.
- After you set the new password, restart MySQL normally so the permission tables load again and password checks resume.
- You need command-line access to your server or computer — you cannot do this through a web interface or remote connection.
Resetting the password on Linux
Open a terminal and stop the MySQL service. The command depends on your Linux distribution, but the most common is sudo systemctl stop mysql. If that does not work, try sudo service mysql stop. You will need administrator (sudo) access to run these commands.
Once MySQL is stopped, start it again with authentication disabled. Run sudo mysqld_safe --skip-grant-tables &. The & at the end runs the command in the background so your terminal prompt returns. Wait a few seconds for MySQL to start.
Now connect to MySQL without entering a password by typing mysql -u root. You should see the mysql> prompt. Run the following commands in order, pressing Enter after each line:
- FLUSH PRIVILEGES;
- ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
- EXIT;
Replace your_new_password with the password you want to use. After you type EXIT, you are back at the terminal prompt. Now restart MySQL normally by running sudo systemctl restart mysql. Test your new password by typing mysql -u root -p, then enter the password when prompted.
Resetting the password on Windows
Open the Services process by pressing Windows key + R, typing services.msc, and pressing Enter. Look for the MySQL service in the list — it is usually called MySQL80 or MySQL57, depending on your version. Right-click it and select Stop.
Open Command Prompt as Administrator. Press Windows key + R, type cmd, right-click the result, and select Run as Administrator. Navigate to your MySQL installation folder, usually C:\Program Files\MySQL\MySQL Server 8.0\bin. Type cd C:\Program Files\MySQL\MySQL Server 8.0\bin and press Enter.
Start MySQL with authentication disabled by typing mysqld --skip-grant-tables and pressing Enter. You will see messages appear but no prompt — that is normal. Leave this window open and open a second Command Prompt window as Administrator.
In the new window, navigate to the same bin folder and type mysql -u root to connect. You should see the mysql> prompt. Run these commands:
- FLUSH PRIVILEGES;
- ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
- EXIT;
Go back to the first Command Prompt window where MySQL is running and press Ctrl + C to stop it. Open Services again, find the MySQL service, right-click it, and select Start. MySQL is now running normally with your new password.
What to do if you cannot stop the MySQL service
On Linux, if systemctl stop mysql does not work, check whether MySQL is actually running by typing ps aux | grep mysql. If you see a process listed, try killing it directly with sudo kill -9 [process_id], where you replace [process_id] with the number shown in the output.
On Windows, if the service will not stop through Services, open Task Manager (Ctrl + Shift + Esc), find any process with mysql in the name, right-click it, and select End Task. Then try stopping the service again.
If MySQL still will not start in skip-grant-tables mode, check the error log. On Linux, this is usually in /var/log/mysql/error.log. On Windows, check the MySQL data folder for a file ending in .err. The error message will tell you what is wrong — often it is a permission issue or a corrupted configuration file.
Preventing this from happening again
Write down your MySQL root password and store it in a password manager like Bitwarden, 1Password, or KeePass. A password manager encrypts your passwords and lets you retrieve them without memorizing them. This is safer than writing passwords on paper or storing them in a text file.
If you manage multiple MySQL servers, create a .my.cnf file on Linux or a my.ini file on Windows with your credentials, then restrict its permissions so only you can read it. On Linux, run chmod 600 ~/.my.cnf after creating the file. This way you can log in without typing the password each time, but the file is protected from other users.
Resetting a password for a user other than root
If you need to reset the password for a different MySQL user (not root), the process is the same up to the point where you connect to MySQL. Instead of the ALTER USER command above, run:
ALTER USER 'username'@'localhost' IDENTIFIED BY 'new_password';
Replace username with the actual username and new_password with what you want to set. If the user connects from a remote host instead of localhost, replace localhost with the hostname or IP address. After you run FLUSH PRIVILEGES and EXIT, restart MySQL normally.
Frequently Asked Questions
Do I need the old password to reset it?
No. The --skip-grant-tables method bypasses the password check entirely, so you can reset any password without knowing the current one. This is why you need direct access to the server — anyone with command-line access can reset any MySQL password.
Will resetting the password affect my databases or data?
No. Changing a password only changes how you log in. Your databases, tables, and all data remain untouched. After you restart MySQL normally, everything works exactly as it did before.
What if I get an error like "Access denied for user 'root'@'localhost'"?
This usually means MySQL restarted in normal mode before you finished. Make sure MySQL is still running with --skip-grant-tables by checking the first terminal or Command Prompt window. If it has stopped, start it again and try the password reset commands once more.
Can I reset the password remotely over SSH or RDP?
Yes, if you have remote command-line access to the server through SSH (Linux) or RDP (Windows). The steps are identical — you are running the same commands on the server itself, just through a remote connection. You cannot do this through a web interface or MySQL client that requires a password.
How do I know if the password reset worked?
After restarting MySQL normally, open a new terminal or Command Prompt and type mysql -u root -p. When prompted, enter your new password. If you see the mysql> prompt, the reset worked. If you see "Access denied", the password did not take or MySQL did not restart properly.