The fastest way to reset your MySQL root password

The method you use depends on whether you still know the current password. If you do, you can change it in seconds using the command line. If you do not, you will need to stop MySQL, restart it in safe mode, and set a new password — a process that takes a few minutes longer but works on Windows, Mac, and Linux.

This guide covers both paths. Start with the section that matches your situation, then follow the steps in order. MySQL will not ask you to confirm the new password, so type it carefully the first time.

Key Takeaways

  • If you know the current root password, you can change it by logging in and running a single command.
  • If you do not know the current password, you must stop the MySQL service, restart it without password checks, and then set a new one.
  • On Windows, you may need to run your command prompt as Administrator for the restart method to work.
  • After you change the password, test it when ready by logging in again to make sure the new one works.
  • The root user in MySQL is separate from the root user on your operating system — changing one does not affect the other.

Changing the password when you know the current one

Open a command prompt or terminal window. On Windows, press the Windows key and type cmd, then press Enter. On Mac or Linux, open Terminal from your Applications folder or by pressing Ctrl+Alt+T.

Type the following command and press Enter:

mysql -u root -p

MySQL will ask you to enter the current password. Type it and press Enter. You should see the mysql> prompt, which means you are logged in.

Now type this command exactly, replacing newpassword with the password you want to use:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';

Press Enter. MySQL will return a message saying the query was successful. Type exit and press Enter to log out. Your new password is now active.

Resetting the password when you do not know the current one

This method stops MySQL, restarts it without password protection, and lets you set a new password. The steps differ slightly between Windows and Mac/Linux.

On Windows: First, stop the MySQL service. Press the Windows key, type services.msc, and press Enter. Find MySQL or MySQL80 (the number depends on your version) in the list, right-click it, and select Stop. Wait for the status to show it has stopped.

Open a command prompt as Administrator. Press the Windows key, type cmd, right-click Command Prompt, and select Run as administrator. Navigate to your MySQL installation folder by typing:

cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"

Adjust the path if your MySQL version is different. Then type:

mysqld --skip-grant-tables

Leave this window open. Open a second command prompt (you do not need Administrator for this one) and type:

mysql -u root

You should see the mysql> prompt with no password request. Type:

FLUSH PRIVILEGES;

Then type:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';

Replace newpassword with your new password. Type exit and press Enter. Go back to the first command prompt window and press Ctrl+C to stop the safe-mode startup. Then restart MySQL normally through Services.

On Mac or Linux: Open Terminal and stop MySQL by typing:

sudo systemctl stop mysql

You will be asked for your computer's password (not the MySQL password). Type it and press Enter. Now restart MySQL in safe mode:

sudo mysqld_safe --skip-grant-tables &

Press Enter. You should see a message that mysqld is running. Now log in without a password:

mysql -u root

Type the same two commands as the Windows version above:

FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';

Type exit and press Enter. Stop the safe-mode process by typing:

sudo killall mysqld

Then restart MySQL normally:

sudo systemctl start mysql

Testing your new password

After you change the password, test it right away to make sure it works. Open a command prompt or terminal and type:

mysql -u root -p

When MySQL asks for the password, type your new one. If you see the mysql> prompt, the password change worked. Type exit and press Enter to log out.

If you get an error saying "Access denied for user 'root'@'localhost'", go back and check that you typed the new password correctly in the ALTER USER command. Spaces and special characters matter.

What to do if you are locked out after changing the password

If you changed the password but now cannot log in, the most common cause is a typo in the new password you set. Repeat the reset process from the section above — you can run the safe-mode startup as many times as you need.

If you are using MySQL on a shared server or through a hosting provider, you may not have permission to stop and restart the service. In that case, contact your hosting provider's support team and ask them to reset the root password for you.

Frequently Asked Questions

Is the MySQL root user the same as my computer's root or Administrator account?

No. The MySQL root user is a database account that only controls access to MySQL databases. Changing the MySQL root password does not affect your computer's Administrator or root account, and you cannot use your computer password to log into MySQL.

Can I change the password for other MySQL users the same way?

Yes. Use the same ALTER USER command but replace 'root'@'localhost' with the username and host you want to change. For example: ALTER USER 'myuser'@'localhost' IDENTIFIED BY 'newpassword';

What if I use MySQL on a Mac and the commands do not work?

MySQL on Mac is often installed through Homebrew or as a DMG package, and the paths may be different. Try typing which mysql in Terminal to find where MySQL is installed, then adjust the paths in the commands above. If you installed it through Homebrew, you can stop it by typing brew services stop mysql.

Do I need to restart my applications after changing the MySQL root password?

Only if those applications connect to MySQL using the root account. Most applications use a separate database user, not root, so they will not be affected. If an process stops connecting to MySQL after you change the root password, check its configuration file to see which MySQL user it is set to use, and reset that user's password instead.

Can I change the password without using the command line?

Yes, if you have MySQL Workbench or another graphical tool installed. Log in, right-click the root user under Administration, select Edit Privileges, and look for the password field. However, the command-line method is faster and works on any computer with MySQL installed.