How to Change or Set the MySQL Root Password

When 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 a Comment