The fastest way to reset MySQL root depends on whether you know the current password
If you have forgotten your MySQL root password, you can reset it without knowing the old one — but the method depends on your operating system and whether MySQL is currently running. On Linux and Mac, you stop the MySQL service, restart it in safe mode, and set a new password. On Windows, the process is similar but uses different commands. If you still remember the password, you can change it in seconds using a single command.
The key difference is that resetting (when you do not know the current password) requires stopping the service and restarting it with special flags that skip authentication. Changing (when you know the current password) happens while the service runs normally. Both are straightforward if you follow the steps in order.
Key Takeaways
- On Linux and Mac, stop MySQL, restart it with the --skip-grant-tables flag, connect without a password, and run FLUSH PRIVILEGES before setting a new password.
- On Windows, use the command prompt to stop the service, restart mysqld with --skip-grant-tables, then connect and reset the password the same way.
- If you remember your current password, use the ALTER USER command while MySQL is running normally — no restart needed.
- After resetting the password, restart MySQL normally so the --skip-grant-tables flag no longer applies and authentication works again.
Resetting the root password on Linux and Mac
Stop the MySQL service first. On Linux with systemd, run sudo systemctl stop mysql. On Mac with Homebrew, run brew services stop mysql. Wait a few seconds for the service to shut down completely.
Start MySQL with the --skip-grant-tables flag, which tells it to ignore the password system. On Linux, run sudo mysqld_safe --skip-grant-tables &. On Mac, run mysqld_safe --skip-grant-tables &. The & at the end runs the command in the background so your terminal prompt returns.
Connect to MySQL without entering a password: run mysql -u root. You should see the mysql> prompt. Now run FLUSH PRIVILEGES; — this tells MySQL to reload the permission tables so that the next command will actually take effect.
Set a new password with ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';. Replace your_new_password with the password you want. Exit with EXIT; or QUIT;. Stop the mysqld process by running sudo killall mysqld on Linux or killall mysqld on Mac. Then restart MySQL normally: sudo systemctl start mysql on Linux or brew services start mysql on Mac.
Resetting the root password on Windows
Open Command Prompt as Administrator. Right-click Command Prompt and select "Run as administrator". Navigate to your MySQL installation directory, usually C:\Program Files\MySQL\MySQL Server 8.0\bin or similar. Run cd "C:\Program Files\MySQL\MySQL Server 8.0\bin", adjusting the version number if needed.
Stop the MySQL service by running net stop MySQL80. The service name may be different — check Windows Services (search for "Services" in the Start menu) to see the exact name if this does not work. Wait for the confirmation message.
Start MySQL with the --skip-grant-tables flag: run mysqld --skip-grant-tables. This window will stay open and show status messages. Do not close it.
Open a second Command Prompt window as Administrator. Navigate to the same bin directory and run mysql -u root. You should see the mysql> prompt. Run FLUSH PRIVILEGES;, then ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';. Exit with EXIT;. Go back to the first Command Prompt window and press Ctrl+C to stop mysqld. Then restart the service normally: net start MySQL80.
Changing the password when you still know it
If you remember your current root password, you do not need to restart MySQL or use any special flags. straightforward connect to MySQL and run one command.
Open a terminal or Command Prompt and run mysql -u root -p. Enter your current password when prompted. Once you see the mysql> prompt, run ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';. Replace your_new_password with what you want. Exit with EXIT; or QUIT;. The new password takes effect when ready.
Why the --skip-grant-tables flag is necessary
MySQL stores user passwords in an encrypted form in the mysql.user table. Normally, you cannot read or modify that table without already knowing the root password — it is a security feature. The --skip-grant-tables flag tells MySQL to ignore all permission checks, so you can connect and modify the password table without authentication.
This is why you must run FLUSH PRIVILEGES; before changing the password. Without it, MySQL is still ignoring the permission system, and your password change might not register. FLUSH PRIVILEGES; tells MySQL to reload the tables and start enforcing permissions again. After you restart MySQL normally, the flag no longer applies and authentication works as it should.
What to do if you get a "command not found" error
If mysqld_safe or mysql is not recognized, MySQL is not in your system PATH. On Linux, try the full path: sudo /usr/sbin/mysqld_safe --skip-grant-tables & and /usr/bin/mysql -u root. On Mac with Homebrew, the paths are usually /usr/local/bin/mysql and /usr/local/bin/mysqld_safe.
If you installed MySQL from a downloaded package rather than a package manager, the bin directory may be in a custom location. Check your installation notes or look in C:\Program Files on Windows or /opt on Linux. Once you find the bin directory, use the full path to the commands.
Securing your new password
After you reset the root password, do not leave it written down on your computer or in a shared document. If you need to store it, use a password manager like Bitwarden, 1Password, or KeePass. These tools encrypt the password and require a master password to access it.
Consider also creating a separate MySQL user account for applications that need database access, rather than using root for everything. Root should be used only for administration. A limited user account reduces the damage if that password is compromised.
Frequently Asked Questions
Can I reset the root password if MySQL will not start?
If MySQL crashes on startup, the issue is usually a corrupted configuration file or data directory, not the password. Check the MySQL error log (usually in /var/log/mysql/error.log on Linux or the MySQL data directory on Windows) to see what is failing. Fix the underlying problem first, then reset the password once MySQL starts.
What if I do not know the MySQL installation directory on Windows?
Open Services (search "Services" in the Start menu), find the MySQL service, right-click it, and select Properties. The "Path to executable" field shows the full path to mysqld. Use the directory containing that file as your bin directory.
Do I need to reset the password if I only forgot part of it?
No. If you remember any part of the password, you can try common variations. If none work, follow the reset steps. There is no way to recover a forgotten password — you can only replace it.
Will resetting the root password affect other user accounts?
No. Resetting root changes only the root password. Other user accounts and their passwords remain unchanged. Applications using other accounts will continue to work.
What if the ALTER USER command does not work?
Make sure you ran FLUSH PRIVILEGES; first. If you are still getting an error, try the older syntax: SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your_new_password');. This works on older MySQL versions, though ALTER USER is preferred on version 5.7 and later.