DEV Community

Cover image for ๐Ÿ” How to Reset MySQL Root Password (Windows - Beginner Friendly)
Theekshana Nuwan
Theekshana Nuwan

Posted on

๐Ÿ” How to Reset MySQL Root Password (Windows - Beginner Friendly)

If you forgot your MySQL root password, follow these simple steps to reset it.


๐Ÿ› ๏ธ What You Need:

  • MySQL installed
  • Access to Command Prompt (as Administrator)
  • A little bit of copy-paste power ๐Ÿ’ช

โœ… Step-by-Step Instructions


1. Create a password reset file

  1. Open Notepad as Administrator

  2. Paste this inside:

   ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
   FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Replace newpassword with your desired password.

  1. Click File โ†’ Save As

  2. Name the file exactly:

   mysql-init.txt
Enter fullscreen mode Exit fullscreen mode
  1. Save it to:
   C:\
Enter fullscreen mode Exit fullscreen mode

So the full path will be C:\mysql-init.txt


2. Stop MySQL

  1. Press Start
  2. Type cmd
  3. Right-click and choose Run as Administrator
  4. Run this command:
   net stop mysql80
Enter fullscreen mode Exit fullscreen mode

3. Start MySQL with the reset file

In the same command prompt, run:

mysqld --init-file=C:\\mysql-init.txt --datadir="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Data" --console
Enter fullscreen mode Exit fullscreen mode

โœ… If you see:

mysqld: ready for connections.
Enter fullscreen mode Exit fullscreen mode

Then it's working! Let it run for 10 seconds, then close the window.


4. Restart MySQL

Open a new command prompt (as Administrator), and run:

net start mysql80
Enter fullscreen mode Exit fullscreen mode

5. Log in with the new password

Open MySQL Command Line and enter your new password when prompted.


๐Ÿงผ Final Step (Optional):

Delete the file you created earlier:

del C:\mysql-init.txt
Enter fullscreen mode Exit fullscreen mode

๐Ÿง‘โ€๐Ÿ’ป Thatโ€™s it!

Youโ€™ve successfully reset your MySQL root password. ๐ŸŽ‰

Let me know if this helped you in the comments or share it with others who might need it!

Top comments (0)