How to reset MySQL password on Windows

This article explains how to reset the MySQL 8 root password on Windows. First, stop the MySQL service through the Services list. Next, create a plain text file containing the ALTER USER statement with your new password. Then open Command Prompt in the MySQL installation's bin folder and start MySQL with the `--init-file` option pointing to that file, waiting for it to finish. After that, log in with the new password to confirm the reset was successful. Finally, delete the reset file for security and restart the MySQL service.

Why Do You Need to Reset the MySQL Password?

Sometimes, after installing MySQL 8.x on Windows, you may:

  • Forget the root password
  • Need to change the root password for security reasons
  • Get errors like "Access denied for user 'root'@"

In these cases, you must reset MySQL password on Windows using the init_file method.

Step to Reset MySQL 8 Root Password

Step 1: Stop the MySQL Service

  • Press Win + R to open the Run dialog.
  • Type services.msc and press Enter to open the Services list.
  • Find the MySQL service (usually named MySQL80 or MySQL).
  • Right-click the service and select Stop.
    1-save

    You must stop the service before using init_file; Otherwise, the reset will fail.

Step 2: Create a Password Reset File

  • Open Notepad.
  • Enter the following line, replacing MyNewPass with your desired password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

2-create-a-text-file
Save the file as:

C:\resetpassword.txt

Make sure it is saved as a plain text file.
3-save-the-file

Step 3: Open Command Prompt in MySQL Directory

  • Press Win + R, type cmd, and press Enter to open Command Prompt.
  • Navigate to the MySQL installation bin folder, e.g.:
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"

4-open-a-console

You must run the command from the MySQL directory, otherwise mysqld may not find the configuration file.

Step 4: Start MySQL with init_file

  • Run the following command (adjust the paths as needed):
mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --init-file=C:\\Users\\Administrator\\Desktop\\resetpassword.txt

5-start

  • Wait until the command finishes executing.

    Note: Use double backslashes \ in file paths.

Step 5: Test the New Password

  • Open a new Command Prompt or MySQL client.
  • Log in with the new password:
mysql -uroot -pHannah_newpasswd

If the login is successful, the root password has been reset.
6-test

Step 6: Cleanup

  • After successful login, delete resetpassword.txt for security.
  • Restart the MySQL service in Services by clicking Start.

Tips for Beginners

  • Make sure the MySQL service is completely stopped before Step 4.
  • Check all file paths carefully; the init-file path must be correct.
  • Avoid complex special characters in the password on the first try; use letters and numbers.
Keywords:

reset MySQL password, mysql forgot root password windows, mysql 8 reset root password, reset mysql password windows, change mysql root password windows, change password mysql 8, change root password mysql 8, forgot root password mysql windows, mysql 8 change password, mysql 8 change root password, mysql 8 set root password

Last Updated:   11/13/2026
Outline