There are several ways of changing the root password of MySQL. Initially, when mysql in first accessed, there are no passwords for the root access, which we all know is not always a good practice. The user root is MySQL’s admin user account, same as in linux/unix.
$ mysqladmin -u root password NEWPASSWORD
If you already have an existing password to root, you may change it by:
$ mysqladmin -u root -p OLDPASSWORD password NEWPASSWORD
This can also be used in changing passwords for normal users:
$ mysqladmin -u username -p OLDPASSWORD password NEWPASSWORD
Using mysql command
Another way is by changing the stored password of users within mysql command.
Login to mysql command:
$ mysql -u root -p
Change to mysql database, since this is where we need to do some changes.
mysql> use mysql;
Use mysql commands to update the password of a user, eg. lhan:
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='lhan';
mysql> flush privileges;