How to Reset MySQL Root Password in Windows Using CMD
Last Updated : 21 Jun, 2025
Ever locked yourself out of your own database? It happens to the best of us! If you’ve forgotten your MySQL root password on a Windows machine, don’t panic. MySQL is a powerful database management system, and the root user has complete control over it meaning losing access can feel like a nightmare. But with the right steps, you can reset that password and regain control in no time.
Learn the process of resetting your MySQL root password using the Command Prompt (CMD). Also, the process we are going to explain in the below article will work for both Windows 11 and Windows 10.
Reset MySQL Root Password in Windows Using CMDSteps 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.
For detailed guide, check out: How to Stop MySQL Server on Windows and Linux?
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.
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.
Also Read
Similar Reads
How to Reset MySQL Root Password in Windows Using CMD? Ever locked yourself out of your own database? It happens to the best of us! If youâve forgotten your MySQL root password on a Windows machine, donât panic. MySQL is a powerful database management system, and the root user has complete control over it meaning losing access can feel like a nightmare.
4 min read
How to Find the Wi-Fi Password Using CMD in Windows Forgotten your Wi-Fi password? Don't worry you're not alone! Whether you're trying to connect a new phone, set up a smart TV, or help a friend get online, remembering complex Wi-Fi passwords can be a headache. Luckily, you don't need to reset your router or dig through old notebooks. Windows has a h
7 min read
How to Remove RAR/WinRAR Password Using CMD? Forgetting the password to your RAR or WinRAR file can be incredibly frustrating, especially when you need to access important data quickly. Fortunately, Command Prompt in Windows provides a powerful and effective way to remove the password from your RAR/WinRAR files without the need for third-party
5 min read
How to Reset Windows Admin Password? If you forgot your Windows administrator password, you might be locked out of your computer and unable to access your files and settings. However, there are some ways to reset your password without losing your data or reinstalling Windows. In this article, we will show you how to reset your Windows
5 min read
How to Stop MySQL Server on Windows and Linux? MySQL is one of the most popular open-source relational database management systems. Whether we are managing a small development setup or a production environment knowing how to start and stop MySQL servers is essential. In this guide, we will learn about the steps to start and stop MySQL servers on
3 min read
How to Change Windows Computer Password using CMD If you are a Windows user, one of the easiest ways to change your password is through the Command Prompt (CMD). This is especially helpful for users who prefer command-line tools or face issues accessing the standard settings menu.In this article, weâll guide you through the steps to change your Win
4 min read