How to Set MySQL root Password CodeUnit 21 FEB 2009

MySQL LogoOne of the most important things you need to do when setting up your new MySQL server instance is to set the password for the root user account. By default, root has no password which is of course quite the security dilemma.

The simplest way to set the root password, or indeed any other user account password, is to make use of the bundled mysqladmin.exe application (found in the bin folder of your MySQL installation directory).

To use, simply open up your command line window and run:

mysqladmin -u root password newpassword

where newpassword is your selected password you wish to apply to the root account.

However, if you already have a password associated with the root account, you then need to add the existing password into the mix, meaning that your application call signature will now look like this:

mysqladmin -u root -poldpassword newpassword

(NOTE: this method applies to any user account, so for example to set the password for the user account craig, I would simply input -u craig instead of -u root in my argument list. Oh, and also notice the lack of a space between the -p switch and the supplied password. I have honestly no idea why this is the case, but it does seem like you need to input it in this fashion.)

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.

  • If you have set a root password, and want to remove it, how do you do that? Just for a dev machine where it’s already locked up of course…