MySQL Change User Password

by Vivek Gite on July 13, 2007 · 8 comments

How do I change user password under MySQL server? I'd like to change a password for user called tom using UNIX / Linux command line option.

First, login to MySQL server, type following command at shell prompt to login as root
$ mysql -u root -p

2) Use mysql database (type command at mysql> prompt, do not include string "mysql>"):
mysql> use mysql;

3) Change password for user tom:
mysql> update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='tom';

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 8 comments… read them below or add one }

1 Michael September 24, 2009

then…

mysql> flush privileges;

Reply

2 Keilaron February 12, 2010
3 mehari January 4, 2011

This is good

Reply

4 amazed January 27, 2011

Very helpful information.

Reply

5 Zipfer October 12, 2011

You forgot – FLUSH PRIVILEGES; after update tables

Reply

6 stevyn December 1, 2011

You legend. Thank you :)

Reply

7 Re@lBanda January 25, 2012

Small modification in 3rd step… according to the mysql documentation, the password should be typed within single quotes instead of double quotes. But double quotes works. Refer the example below…

mysql> UPDATE user SET Password=PASSWORD(‘NEW-PASSWORD-HERE’) WHERE User=’tom’;

Another thing to mention, make sure you change the password for both the local and remote users because if a remote application server (ex-jboss) or in php connecting to mysql server it will still be needed the old password since it is remaining unchanged.

So according to this scenario the proper commands should be…

mysql> UPDATE user SET Password=PASSWORD(‘NEW-PASSWORD-HERE’) WHERE User=’tom’ AND Host=’local’;

mysql> UPDATE user SET Password=PASSWORD(‘NEW-PASSWORD-HERE’) WHERE User=’tom’ AND Host=’%';

Reply

8 Re@lBanda January 25, 2012

Forgot to mentioned….

the first single command will do the password change for local and remote which is..

mysql> UPDATE user SET Password=PASSWORD(‘NEW-PASSWORD-HERE’) WHERE User=’tom’;

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 11 + 2 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: