Subscribe to How-To Geek

Recommended: Click Here to Run a Free Scan for Common PC Errors   [Sponsored Link]

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

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 09/11/06 and tagged with: MySQL

Comments (3)

  1. Lior

    I don't know why, but I needed to use
    mysqladmin -u root -p"newpassword" -h host_name password “newpassword”
    instead your second command.

  2. xunshirine

    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.

  3. Steven Bao

    Works like a charm on MySQL5. Thanks for the tip.


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.