Monday, December 5, 2011

Changing user password

When you install mysql using yum on a rpm based machine, it's default root password is empty. To change it you can use mysqladmin command. The command is like this:
mysqladmin -u root password NEWPASSWORD
if you want to change a root with a existing password, you can use this:
mysqladmin -u root -p 'oldpassword' password NEWPASSWORD

Changing MySQL password for non-root user

To change a normal user password you can use the same syntax as changing root with existing password:
mysqladmin -u username -p 'oldpassword' password NEWPASSWORD

Chaning User Password using MySQL command

You can also used the MySQL command line to update user's password, MySQL stores username and passwords in a table inside MySQL database.

  1. Login to mysql server.
  2. Use mysql database.
  3. change password for username by entering:  update user set password = PASSWORD("NEWPASSWORD") where user='username';
  4. Lastly, restore the privileges: flush privileges;