There might arise a situation where you need to reset the root password for your MySQL database.  It can be because you forgot your password or you need to change the password for security reasons. 

In this article, we will look into the process of resetting the MySQL password using Windows cmd. To do so follow the below steps:

Step 1: Stop the MySQL server

Begin by checking if you’re logged in as an administrator.

Press Win+R (hold the Windows/Super key, and press “r”.) Once the “Run” box appears type:


  1. Click OK.
  2. 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

  1. Click on the menu and search for Notepad.
  2. Alternatively, you can use the path: Menu > Windows Accessories > Notepad.

Step 3: Create a New Text File with the Password Command

Enter the following line into the text editor:

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

Make sure you keep the quote marks and semicolon. Replace NewPassword with the password of your choice.

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

  1. Press Ctrl+Shift+Esc.
  2. Then, click on the File menu > Run new task.
  3. Type cmd.exe, and check the box to run as administrator.
  4. 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" or C:\Program Files\BioStar 2(x64)\ta\mariadb-10.1.10-winx64

Accordingly, the command line will show that you’re working in this folder.

Enter the following:

mysqld --init-file=C:\\mysql-init.txt

mysqld --init-file=C:\\mysql-init.txt

Note that there are two slashes after the C: prompt.

Also, if you chose a different name in Step 2, use the same name after the double slash.