Pages

Saturday, September 8, 2007

Different tricks: How to Change the MySQL Password using command prompt

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 pcsmitpra):

$ mysqladmin -u pcsmitpra -p oldpassword newpass

Method # 2:
MySQL stores username and passwords in user table within MySQL database. You can directly update password using following method to update or change password for user pcsmitpra:

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 pcsmitpra:

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

4) Reload privileges (very important), this method you need to use while using PHP or Perl scripting.:

mysql> flush privileges;
mysql> quit

Your comments are valuable for me.

No comments:

Post a Comment