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
Open Notepad as Administrator
Paste this inside:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
FLUSH PRIVILEGES;
π Replace newpassword with your desired password.
Click File β Save As
Name the file exactly:
mysql-init.txt
- Save it to:
C:\
So the full path will be C:\mysql-init.txt
2. Stop MySQL
- Press
Start
- Type
cmd
- Right-click and choose Run as Administrator
- Run this command:
net stop mysql80
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
β
If you see:
mysqld: ready for connections.
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
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
π§βπ» 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)