How to reset MySQL 8.x password on Windows

If you forgot the root password in MySQL 8 on your Windows server, don’t worry. This guide will show you how to reset MySQL 8 root password on Windows step by step. Even if you are a beginner, you’ll be able to follow along and successfully change the MySQL root password.

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.
Last Updated:   07/08/2026
Outline