How to change root password in mysql ?

February 27th, 2008

You might have installed mysql and would like to change / set password for root. Password for root might be empty initially.. So this is what you need to do.

There is a mysqladmin command in unix,linux,freebsd to administer mysql.

Setting root password for mysql for the first time

Here the initial password is empty. Type the following comman.

mysqladmin -u root password YOURNEWPASSWORD

Here YOURNEWPASSWORD is the password you would like to set.

Alternatively, on command line, log in to mysql as root. This time password is not required. Then run an update query to update the password of root.

mysql -u root

update mysql.user set password=’NEWPASSWORD’ where user=’root’

Changing root/user password

Run the following command to change password for root. Replace root with the user name of other users in order to change their password.

mysqladmin -u root OLDPASSWORD NEWPASSWORD

OLDPASSWORD is old password and NEWPASSWORD is the new password.

Alternatively you can run the above query to modify the user password (see above).

Leave a Reply