MySQL change root password

MySQL change root password

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 have nothing to do with each other (indeed some admin removes root account and setup admin as mysql super user). Method # 1 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: To change a normal user password you need to type (let us assume you would like to change password for eric):
$ mysqladmin -u eric -p oldpassword newpass
Method # 2: MySQL stores username and passwords in user table inside MySQL database. You can directly update password using following method to update or change password for user eric: 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 eric:
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='eric';
4) Reload privileges (very important):
mysql> flush privileges;
mysql> quit
This method you need to use while using PHP or Perl scripting.

Leave a Reply

Your email address will not be published.

My new Snowflake Blog is now live. I will not be updating this blog anymore but will continue with new contents in the Snowflake world!