When you first install mysql, there won’t be a mysql password set for you. In order to set a mysql root password, you can use the mysqladmin command.
Create MySQL Root Password
Firstly change to the folder where your mysql is installed and enter the following command, where mypassword is the new password to use for mysql.
mysqladmin -u root password 'mypassword'
Update MySQL Root Password
If you already set a root password for mysql and would like to update it, you can use the following command where oldpass is your original password and newpass is the new root password to use for mysql.
mysqladmin -u root -p 'oldpass' password 'newpass'
Change Password For Other MySQL Users
You will notice that the above two commands we specify the username as root. What this means is that we can use the same commands to change a mysql password for other users. Use the following command where someuser is the mysql username you want to change the password for, oldpass is your original password and newpass is the new password for that mysql user.
mysqladmin -u someuser -p 'oldpass' password 'newpass'