There will come a time when you would want to change your MySQL password. There could be many reasons why you would want to do that:
- Your password has been leaked or compromised.
- You believe in regularly changing your password.
- Or, it could any other reason.
In my case, I installed MySQL in my office PC for practice. However, while setting the root password, I set the password, which I use in my home PC. Now, I have python files in my office PC and all those files have my personal password. This made me very uncomfortable as I didn’t want anybody to know about that. So, I decided to change it to something very simple and ‘generic’.
So, I will tell you the easiest way to change the password. Just follow the steps below and you’ll be able to change your MySQL password in a breeze.
Steps to change MySQL root password
Step 1 : Open CMD by pressing “Windows Key + R” keys.
The following will pop up.

Type “CMD” in the filed and press ‘OK’.
Step 2 : When CMD opens, type the following command to change the directory.
|
1 |
cd C:\Program Files\MySQL\MySQL Server 8.0\bin |
In your case too, the directory will be similar except for the extent of ‘MySQL Server 8.xx’. So just check it & enter accordingly.
Step 3 : Now, enter the following .
|
1 |
mysql -u root -p |
After pressing ‘Enter’ your will see the following:
![]()
It is asking you to enter the password.
Step 4 : Enter your old password to get into MySQL
Upon entering the old password and pressing ‘enter’ you’ll see the following displayed.

That’s good. You’ve entered MySQL.
Now, you need to change your password. It is very simple & you just need to do two things:
- First would be to flush privileges
- & second would be to set your new password.
So, let’s see how that is done.
Step 5 : Enter the following command:
|
1 |
mysql> flush privileges; |
Upon pressing ‘Enter’ you’ll get the confirmation.
![]()
Step 6 : Now, change your password by entering the following command. Here, the field ‘new_password’ is the for the new password you want to keep.
|
1 |
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; |
Upon pressing ‘Enter’ you’ll get the confirmation.
![]()
Step 7 : Now, quit mysql, by typing the following command.
|
1 |
mysql> \quit |
![]()
MySQL will bid you bye.
Step 8 : Now, re-enter MySQL by typing the following command.
|
1 |
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p |
After pressing ‘Enter’ it will ask you to provide the password.
![]()
Step 9 : Enter your new password to enter into MySQL
As you enter, you will be greeted with the follwing message.

This means the job is done. You’ve successfully entered MySQL with changed password.
Step 10 : Now, check your MySQL databases, by typing the following command.
|
1 |
mysql> show databases; |
In my case, it shows the following:

So, now you’re done. You have successfully changed your MySQL password and from now onwards, you can enter MySQL with your new password.