How to change the default MySQL root (or other user) password
In fresh MySQL installations, the default root password is set to "" (nothing). While this might be acceptable on a development machine, it's a huge security risk on production servers.
To set an initial MySQL root password from the command line
Open a new Terminal window and enter (replacing "{newpassword}" with the new password):
mysqladmin -u root password {newpassword}
To change the password for any user account (including root) that already has a password
Open a new Terminal window and enter the following line, then enter the user's current password when prompted:
mysqladmin -u {user} -p password {newpassword}
To change the password for a user with a SQL command
Open a new Terminal window and log into the mysql client as root:
mysql -u root -p
When prompted, enter the root account's password, then select the mysql database:
USE mysql;
Change the password for a specific user by entering:
UPDATE user
SET password = PASSWORD("{newpassword}")
WHERE User = '{user}';
Finish the change by refreshing user privileges and quitting the mysql client:
FLUSH privileges;
quit