Home » Database, Linux

How to Change or Set the MySQL Root Password

8 May 2011 No Comment

How to Change or Set the MySQL Root PasswordWhen you are setting up a database, it comes standard with the sa account that has access to everything. Unless you want to get comprised, you should change it to a difficult password.

On some databases such as mySQL, the sa account is called root and it has a blank password.

Changing the root password for mySQL can be done from the command line using the mysqladmin utility. You can use this utility to change other user accounts but in this instance, we are specifying the root account.

The syntax for changing the root password using the mysqladmin utility is as follows:

mysqladmin -u root password <new_password>
mysqladmin -u root -h <host_name> password <new_password>

Where <new_password> is the password you want to change it to and <host_name> is the host of the machine running the mySQL server.

This is an example for changing the root password.

mysqladmin -u root password H@rd2Gues$
mysqladmin -u root password -h localhost H@rd2Gues$

After changing the root password, you need to restart the mySQL process for the changes to take effect.

sudo /etc /init.d/mysql restart

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.