How to Reset MySQL Password on Windows
Reset a forgotten MySQL root password on Windows using a reliable MySQL recovery method with an init file.
Introduction
If you forgot your MySQL root password on Windows, you can reset it by creating a temporary MySQL init file and starting MySQL in recovery mode.
Open Notepad as administrator
Open the Windows Start Menu, search for Notepad, right-click it, and select Run as administrator.
Create the MySQL reset file
Paste the SQL password reset command into Notepad.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password_here';
Save the reset file
Save the file as mysql-reset.txt directly on the C:\ drive.
Stop the MySQL service
Open Command Prompt as administrator and stop the MySQL service before starting recovery mode.
net stop MySQL80
Open the MySQL bin directory
Navigate to the MySQL bin folder so you can run mysqld directly.
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
Start MySQL with the init file
Start MySQL using the real MySQL configuration file and the temporary init file.
mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file="C:\mysql-reset.txt" --console
Stop the temporary MySQL recovery session
After the password reset command has executed successfully, stop the temporary MySQL session.
Start MySQL normally
Restart the MySQL service normally so password protection is enabled again.
net start MySQL80
Delete the temporary reset file
Remove the reset file so the password reset command cannot run again accidentally.
del C:\mysql-reset.txt