In the previous post, we saw how to change MySQL password using mysqladmin command at shell prompt. But there is another way to do it by updating the MySQL database. As usernames and passwords are stored in a user table in the MySQL database so you can directly change the password of any user by following the below-given method.
First, you need to login into the MySQL server and type the following command
$ mysql -u root -p
For using MySQL database you need to type the following command
mysql> use mysql;
Suppose that you want to change the password of a user having username ‘XYZ’, then type the following command
mysql> update user set password=PASSWORD(“NEWPASSWORD”) where User=’XYZ’;
After doing these changes it’s recommended to reload privileges before you quit so type the following command.
mysql> flush privileges;
Now to exit MySQL use the following command