In 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 MySQL database so you can directly change password of any user by following the below given method.
First you need to login into 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 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 following command

mysql> quit