LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

How to Reset MySQL Root Password on Windows Using an Init File

0 comments
Forgetting your MySQL root password can be frustrating — but don’t worry! If you're on Windows, there's a simple way to reset it using an init file method. Here's how you can do it step by step.

Step 1: Create the Reset File

First, create a text file called reset.txt at the root of your C: drive with the following content:

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

Replace 123456 with your new root password.

Step 2: Find Two Important Paths

You’ll need to know where these two files are:

  • mysqld.exe – MySQL server executable
  • my.ini – MySQL configuration file

Open Command Prompt as Administrator then run these:

where mysqld

Example Output:

C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe

dir \my.ini /s /b

Example Output:

C:\ProgramData\MySQL\MySQL Server 8.0\my.ini

Step 3: Stop MySQL Service

Before applying the reset, stop the MySQL service:

  • Press Win + R, type services.msc, and press Enter.
  • Find MySQL Server 8.0
  • Right-click and choose Stop

Step 4: Start MySQL with Init File

Open Command Prompt as Administrator and run:

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file="C:\reset.txt" --console

This tells MySQL to execute the command in reset.txt during startup.

Step 5: Restart MySQL Normally

  • Once the command is executed, press Ctrl + C to stop the server. Then:
  • Go back to services.msc
  • Start MySQL Server 8.0 again

Step 6: Login with New Password

Now you can log in to MySQL using your new root password, open Command Prompt:

mysql -u root -p

Final Step: Clean Up

Don’t forget to delete the reset.txt file after the reset for security reasons.

No comments:

Post a Comment