This is a website by Willem van Zyl

I'm a project manager, software developer, Apple evangelist and geek from South Africa. I'm passionate about web and mobile application development, usability, productivity, physics, astronomy, science fiction and fantasy.

If you would like to contact me, message me on Twitter or send me an email.

How to change the default MySQL root (or other user) password

20 May 2009

In fresh MySQL installations, the default root password is set to "" (nothing). While this might be acceptable on a development machine, it's a huge security risk on production servers.

To set an initial MySQL root password from the command line

Open a new Terminal window and enter (replacing "{newpassword}" with the new password):

mysqladmin -u root password {newpassword}

To change the password for any user account (including root) that already has a password

Open a new Terminal window and enter the following line, then enter the user's current password when prompted:

mysqladmin -u {user} -p password {newpassword}

To change the password for a user with a SQL command

Open a new Terminal window and log into the mysql client as root:

mysql -u root -p

When prompted, enter the root account's password, then select the mysql database:

USE mysql;

Change the password for a specific user by entering:

UPDATE user
   SET password = PASSWORD("{newpassword}")
 WHERE User = '{user}';

Finish the change by refreshing user privileges and quitting the mysql client:

FLUSH privileges;
quit
Do you like this? Share it:

Copyright © Geekology 2011. All Rights Reserved.

Hosted by Code. Like. Clockwork.