Change or Set the MySQL Root password
For every database, you should set the root or sa passwords to something other than the default, unless you want to get hacked. For mysql, the system administrator user is called root. You will use the mysqladmin utility from a command line to set the new password. Notice that there are two commands to be run.
Syntax:
mysqladmin -u root password “newpassword”
mysqladmin -u root -h host_name password “newpassword”
Example:
mysqladmin -u root password ws8dr8as3
mysqladmin -u root -h localhost password ws8dr8as3
You will also want to restart the database server after running this command
sudo /etc/init.d/mysql restart

Daily Email Updates
You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


I don’t know why, but I needed to use
mysqladmin -u root -p”newpassword” -h host_name password newpassword
instead your second command.
After the second command terminal gives that
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@'localhost’ (using password: NO)’
How can I solve that?
Thanks in advance.
Works like a charm on MySQL5. Thanks for the tip.
Resetting the password this way will put the password in your shell’s history:
$ history | grep mysqladmin
For that reason, you might want to consider setting/resetting the password from the mysql client:
$ mysql -u root mysql
mysql> SET PASSWORD FOR root@localhost=PASSWORD(’newpasswordgoeshere’);
That will also leave it in a file, the .mysql_history file.
Good Stuff poeple