How to Set MySQL root Password

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.)

You might also enjoy:

About Craig Lotter

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.
This entry was posted in Technology & Code, Tutorials. Bookmark the permalink.
    blog comments powered by Disqus