When you installed MySQL, you would have been asked for a root password. If you were testing or something similar, you may have used an empty password. This is all well and good until you need to put your server into production. So, how do you create one?

> mysqladmin -u root password NEWPASSWORD

This will assign the root user, the password in NEWPASSWORD

But, what if you want to change the root’s password?

> mysqladmin -u root -pOLDPASSWORD password NEWPASSWORD


> mysqladmin -u root -pabcdefg password gfedcba

The above example will change the root’s password (if it is right) from abcdefg to gfedcba (I know this isn’t a very strong password, but its only an example)

You can of course, log into MySQL to change the password for any user by following these commands:

> mysql -u root -pADMINPASSWORD
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD('NEWPASSWORD') WHERE user = "root";


If you forget your root password, then see my post on forgotten MySQL root password


By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.