MySQL change root password
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:
- What is My root Password for MySQL Database Server?
- Change MySQL root password
- What is my root password for MySQL?
- How do I access MySQL server from the shell prompt (command line)?
- Redhat Enterprise Linux (RHEL) install and configure MySQL database
Discussion on This FAQ
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!
Tags: mysqladmin_command, mysql_admin, mysql_database, mysql_password, mysql_server, root_password, sql_command ~ Last updated on: September 29, 2007



February 27th, 2007 at 5:15 am
[...] Ref: mysql-change-root-password [...]
June 5th, 2007 at 3:34 pm
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)
June 6th, 2007 at 10:44 am
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
June 18th, 2007 at 11:18 am
computers can be sucha pain..!!
THANKS!
December 20th, 2007 at 4:57 pm
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
February 6th, 2008 at 6:37 am
The information on your website has helped me. Thanks.
Best Wishes,
K.Ramanathan
March 17th, 2008 at 11:49 pm
Thank you very much, this information was usefull!
- Alexander Elo
April 25th, 2008 (3 weeks ago) at 5:35 pm
If I forgot my mysql password? how is it going?, because there is a step that need an old mysql password.
April 25th, 2008 (3 weeks ago) at 7:02 pm
Go here to recover mysql password.
May 14th, 2008 (2 days ago) at 2:33 am
Worked like a charm, thnx.