About Linux FAQ

Browse More FAQs:

MySQL change root password

Posted by Vivek on Monday January 2, 06 @11:17 pm

Q. How do I change MySQL root password under Linux, FreeBSD, OpenBSD and UNIX like operating system over ssh / telnet session?

A. Setting up mysql password is one of the essential tasks. root user is MySQL admin account. Remember Linux / UNIX login root account for your operating system and MySQL root are different. They are separate and nothing to do with each other (indeed some admin removes root account and setup admin as mysql super user).

mysqladmin command to change root password

If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:

$ mysqladmin -u root password NEWPASSWORD

However if you want to change (or update) a root password, then you need to use following command:

$ mysqladmin -u root -p oldpassword newpass

Enter password:

Change MySQL password for other user

To change a normal user password you need to type (let us assume you would like to change password for vivek):

$ mysqladmin -u vivek -p oldpassword newpass

Changing MySQL root user password using mysql sql command

This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:

1) Login to mysql server, type following command at shell prompt:

$ mysql -u root -p

2) Use mysql database (type command at mysql> prompt):

mysql> use mysql;

3) Change password for user vivek:

mysql> update user set password=PASSWORD("NEWPASSWORD") where User='vivek';

4) Reload privileges:

mysql> flush privileges;
mysql> quit

This method you need to use while using PHP or Perl scripting.

See also:

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Linux / UNIX FAQ:

Discussion on This FAQ

  1. Memorias inconclusas » Blog Archive » Cambiar password de MySql Says:

    [...] Ref: mysql-change-root-password [...]

  2. Tabitha Says:

    I got an error trying to use your method to change the root password using mysqladmin. I did some checking and found that the following method worked.

    mysql> mysqladmin -u molly -p password NEWPASSWORD
    (replacing NEWPASSWORD with the desired password, you will be prompted to enter the current password)

  3. Samuel Says:

    I am using the latest MySQL, the codes above didn;t work for me, please if you have the correct code to use. I want to change the root password to null. Just like it came.

    Thanks

  4. Edd Says:

    computers can be sucha pain..!!

    THANKS!

  5. yesh Says:

    Yessssss… same for me…
    It will not work.
    I use WAMPSERVER 2.0
    I get following error in Mysql:

    ERROR 1064 (42000): You have an error in you SQL syntax; check the manual that corresponds to your MySql server version for the right syntax to use near ‘$ mysql -u root -p
    mysql> use mysql
    mysql> update user set password=PASSWORD(”NE’ at line 1

    Very annoying

  6. K.Ramanathan Says:

    The information on your website has helped me. Thanks.

    Best Wishes,
    K.Ramanathan

  7. Alexander Elo Says:

    Thank you very much, this information was usefull!

    - Alexander Elo

  8. hardyboyz Says:

    If I forgot my mysql password? how is it going?, because there is a step that need an old mysql password.

  9. vivek Says:

    Go here to recover mysql password.

  10. ryan Says:

    Worked like a charm, thnx.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , ~ Last updated on: September 29, 2007

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.