How to Change or Reset 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 usually called root, but sometimes it’s called admin or something else.

Here’s the two methods to reset the password:

From the Command Line

mysqladmin -u root password “newpassword”

mysqladmin -u root -h host_name password “newpassword”


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

Alternative Method (from MySQL Client)

If you don’t have access to the server, or you’re running on Windows and you already know the password, you can connect to the server as root and then use the following command:

mysql> SET PASSWORD FOR root@localhost=PASSWORD(’newpassword’);

Enjoy your new MySQL Password!

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.