🔐 How I Recovered My MySQL Root Password on Windows (MySQL 8.0) — Step by Step

Published: (January 8, 2026 at 02:23 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Cover image for 🔐 How I Recovered My MySQL Root Password on Windows (MySQL 8.0) — Step by Step

Overview

Losing your MySQL root password can feel like the end of the world — especially when you’re a student or a fresher and MySQL just refuses to connect. I recently faced this exact issue on Windows + MySQL 8.0, spent hours getting errors like:

ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306'

After a lot of trial and error, I finally fixed it without losing any data. Here’s the exact method that worked 100 % for me.

Problem Summary

  • OS: Windows 10/11
  • MySQL Version: 8.0.x
  • Issue: Forgot MySQL root password; MySQL service wouldn’t allow login.
  • Tried: --skip-grant-tables method kept failing.

The Solution That Actually Worked (Init File Method)

This method is safe, official, and works even when other methods fail.

Step 1: Stop MySQL Service

  1. Press Win + R, type services.msc and hit Enter.
  2. Locate MySQL80 (or the service name for your installation).
  3. Right‑click → Stop.

Step 2: Create a Password Reset File

  1. Open Notepad.
  2. Paste the following SQL:
ALTER USER 'root'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'TempPass@123';
  1. Save the file as reset.sql (make sure the extension is .sql, not .txt) in:
C:\Users\<your‑username>\Documents\

Step 3: Start MySQL Using the Init File

Open Command Prompt as Administrator and run:

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

Then start MySQL with the init file:

mysqld --init-file="C:\Users\<your‑username>\Documents\reset.sql" --datadir="C:\ProgramData\MySQL\MySQL Server 8.0\Data"

What Should Happen

  • The terminal appears “stuck” (no prompt).
  • No errors are shown.
  • MySQL server is running, meaning the password reset command was executed successfully.

Step 4: Stop the Temporary Server

Press Ctrl + C in the terminal to terminate the process, then close the window.

Step 5: Start MySQL Normally

  1. Open services.msc again.
  2. Start MySQL80.

Step 6: Login with the New Password

mysql -u root -p

Enter the password you set in reset.sql (TempPass@123). You should see:

Welcome to the MySQL monitor

Step 7 (Important): Set Your Own Secure Password

Inside the MySQL monitor, run:

ALTER USER 'root'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'YourOwnStrongPassword@123';
FLUSH PRIVILEGES;

Delete the reset file you created:

del "C:\Users\<your‑username>\Documents\reset.sql"

Common Mistakes I Made (So You Don’t)

  • Trying to connect when the MySQL server wasn’t running.
  • Using the wrong datadir.
  • Forgetting to adjust Windows file permissions.
  • Assuming a “stuck” terminal meant an error (it actually indicates success).

Final Thoughts

  • If you’re stuck with MySQL root access on Windows: don’t panic, don’t reinstall MySQL, and don’t delete data.
  • The init‑file method is the most reliable fix I’ve found.

If this helped you, feel free to share it—it might save someone hours of frustration.

Back to Blog

Related posts

Read more »

NodeJS 101 — Part 2 MySQL

🚀 การสร้าง API โดยใช้ JavaScript Node.js Express คู่มือการพัฒนา RESTful API แบบครบวงจรด้วย Node.js, Express, Sequelize และ MySQL ! https://media2.dev.to/dynam...