MySQL stores username and passwords in the user table inside MySQL database. You can directly update or change the password using the following method:
Login to your server, type the following command at prompt:
$ mysql -u root -p
Use the mysql database;
mysql> use mysql;
Change password for user root, enter:
mysql> update user set password=PASSWORD("NEW-PASSWORD") where User='root';
Finally, you need to reload the privileges:
mysql> flush privileges; mysql> quit