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
- --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
- Press Win + R → type services.msc
- Find MySQL80
- Right-click → Stop
📝 Step 2: Create a Password Reset File
- Open Notepad
- Paste this:
ALTER USER 'root'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'TempPass@123';
- Save the file as:
reset.sql
- Save it in:
C:\Users\<your-username>\Documents\
⚠️ Make sure it’s reset.sql, not reset.sql.txt
▶️ 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:
mysqld --init-file="C:\Users\<your-username>\Documents\reset.sql" --datadir="C:\ProgramData\MySQL\MySQL Server 8.0\Data"
✅ What should happen
- Terminal looks “stuck”
- No errors
- MySQL server is running
👉 This means the password reset command was executed successfully.
⛔ Step 4: Stop Temporary Server
Press:
CTRL + C
Close the terminal.
▶️ Step 5: Start MySQL Normally
- Open services.msc
- Start MySQL80
🔓 Step 6: Login with New Password
Open CMD:
mysql -u root -p
Enter the password you set in reset.sql.
If you see:
Welcome to the MySQL monitor
🎉 You’re back in.
🔐 Step 7 (Important): Set Your Own Secure Password
Inside MySQL:
ALTER USER 'root'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'YourOwnStrongPassword@123';
FLUSH PRIVILEGES;
🧹 Cleanup (Optional but Recommended)
Delete the file:
reset.sql
You don’t need it anymore.
🧠 Common Mistakes I Made (So You Don’t)
❌ Trying to connect when MySQL server wasn’t running
❌ Using wrong datadir
❌ Forgetting Windows permissions
❌ Assuming “terminal stuck” = error (it’s actually success)
✅ Final Thoughts
- If you’re stuck with MySQL root access on Windows:
- Don’t panic
- Don’t reinstall MySQL
- 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.
Top comments (0)