How to Reset MySQL Root Password on Windows

In this blog, we will learn how to reset password MySQL Password in Windows. Sometime, we forgotten the password which we have set in MySQL and it gets difficult to recover the password. Here i will show you have recover your forgotten password in Windows with very simple and easy to understand steps.

Resetting the MySQL root password on Windows involves a slightly different process compared to How to Reset Root MySQL Password on Ubuntu 22.04. Here’s how you can do it:

Step 1: Stop MySQL Service: Open Services or Type services.msc in Run Dialog (⊞ Win+R) and search for MySQL or MySQL80 or anything which starts with MySQL. Right Click and Stop it.

Step 2: Create Initialization File: Create a new file named mysql-init.txt in your C:\ directory (or any directory of your choice). Add the following SQL command to set the new root password. Replace ‘new_password’ with your desired password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Remember to replace ‘new_password’ with your desired password throughout the process.

Step 3: Start MySQL in Safe Mode: Start MySQL in safe mode, which doesn’t require a password:

Open Command Prompt in Administrator Mode and change path in cmd to C:\Program Files\MySQL\MySQL Server 8.0\bin

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

Once your are inside folder, type the bellow command

mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file="C:\mysql-init.txt" --console

This command starts MySQL with an init-file argument that points to a file (mysql-init.txt) where you will define a new root password. Make sure to replace the paths with your actual MySQL installation directory.

How to Reset MySQL Password in Windows.

Congratulations you have successfully changed the root password of your MySQL in Windows.

Step 4: Connect to MySQL: Open a new Command Prompt window (not as administrator). You can now connect to MySQL using the new password:

mysql -u root -p

Enter the new password when prompted.

Step 5: Connect to MySQL: Start MySQL Service: After verifying that you can log in with the new password, start the MySQL service normally. Open Services or Type services.msc in Run Dialog (⊞ Win+R) and search for MySQL or MySQL80 or anything which starts with MySQL. Right Click and Start it.