Forgetting your MySQL root password can be frustrating, but resetting it doesn’t have to be complicated. If you’re using Windows, you can easily reset the MySQL root password using CMD (Command Prompt). This article will walk you through the steps to change the MySQL root password using CMD, ensuring that you regain access to your MySQL server without a hitch. Whether you’ve forgotten your password or just want to update it for security reasons, this MySQL root password reset for Windows process will help you get back on track.
How to Reset MySQL Root Password in Windows using CMD? #
Note: Before Resetting MySQL Root Password, make sure that you are Log in to your system as Administrator.
Step 1: Stop the MySQL server #
- Press Win+R and type the following command in the Run box and Click OK.
Command: services.msc

- Scroll down the list of services to find the MySQL service. Right-click that entry then left-clicks Stop.
Step 2: Launch a Text Editor #
- Click on the menu and search for Notepad.
- Alternatively, press Ctrl + Alt + N to open Notepad.
Step 3: Create a New Text File with the Password Command #
Enter the following command to the text editor:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
Note: Copy-paste this command to avoid any mistake. Make a new password and Replace ‘NewPassword’ with it.

- Use the File > Save As menu to save the file to the root of your hard drive (C:\ ). Choose a filename that makes sense, such as mysql-init.txt.
Consequently, the localhost command will make the password change on your local system. If you’re trying to change the password on a system over the network, substitute the hostname for localhost
Step 4: Open a Command Prompt #
- Press Ctrl+Shift+Esc.
- Then, click on the File menu > Run new task.
- Type cmd.exe, and check the box to run as administrator.
- Click OK.
Step 5: Restart the MySQL Server with Your New Config File #
- Navigate to the MySQL directory using the command prompt:
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
Accordingly, the command line will show that you’re working in this folder.
- Enter the following:
mysqld --init-file=C:\\mysql-init.txt
Note:
- There are two slashes after the C: prompt.
- Also, if you choose a different name in Step 2, use the same name after the double slash.
Step 6: Clean up #
Now, you can log into your MySQL server as root using the new password.
- Double-check to make sure it works. If you have unique configuration options (such as launching MySQL with a -defaults-file option), go ahead and do so.
- Once MySQL launches, and you’ve confirmed the password change, delete the C:\myswl-init.txt file.
At this stage, you have successfully changed MySQL root password.
Conclusion #
Resetting your MySQL root password on Windows is a straightforward process when using the Command Prompt. By following the steps outlined in this guide, you can efficiently recover your MySQL root password using CMD and regain control over your database. Whether you’re a seasoned MySQL user or a beginner, this method ensures that you can handle password issues without unnecessary hassle. Keep this guide handy for future reference, so you’re always prepared to reset your MySQL root password in Windows using CMD.
Credit by : Webstation