Changing Mysql password is one of the very essential & critical task which you need to do while taking care of the database. By default “root” comes up with admin privileges and no password for root. Just to be clear, this root user is different from what your Linux/Unix system root user is, so changing password for this user, won’t change password for root user for operating system.

Mysql stores the password in the “user” table in “mysql” database. To change/update a password, we need to update that table data. That can be done either at the OS level with “mysqladmin” command or either at the Mysql level with sql command.

Changing Password with mysqladmin command:

mysqladmin command is one way to interact with the information stored in user table from OS command line interface. If you have done a fresh installation of Mysql, then there is no password set for root user. To set a new password for the same, use this command:

$ mysqladmin -u root password NEWPASSWORD

This will create the password for the root user.

Also, to change the password of root user, one needs to use the command like this:

$ mysqladmin -u root -p'oldpassword' password 'NEWPASSWORD'

If you don’t provide any old password with “-p”, then it will prompt you for a pasword after executing this command.

To change the password of normal user, same procedure is followed:

$ mysqladmin -u napster -p'oldpassword' password 'NEWPASSWORD'

Changing password with Mysql sql command:

You can also update the information in the user table with the sql command. Following steps needs to be followed for the same.

Login to Mysql server

$ mysql -u root -p'password'

Go to mysql database

mysql> use mysql;

Change password for napster user

mysql> update user set password=PASSWORD("NEWPASSWORD") where user="napster";

Now reload the privileges, which will update the cache and flush the old password

mysql> flush privileges;

mysql> ctrl+D

Recovering a lost password is different topic which is covered in this article:

Recover Mysql Root Password

If you enjoyed this post, make sure you subscribe to my RSS feed!!!!