Database

How to Change MySQL User Password

Question : I would like to change password for user called “neo” using MySQL command. How do I change user’s password on MySQL server.

Answer : If you want to change password for MySQL user you need to use MySQL command on Linux or Unix operating system. Type the below command at the shell prompt to login as a root user.

Change MySQL User Password

Change the MySQL user password using the below method.

a) Open the bash shell and connect to the server as root user.

mysql -u root -h localhost -p

b) Run command:

ALTER USER 'userName'@'localhost' IDENTIFIED BY 'New-Password-Here';

MySQL Command to Change User Password

Login as root from the shell.

# mysql -uroot -p

Now switch to MySQL database.

mysql> use mysql;

The syntax is as follows for MySQL database server version 5.7.5 or older:

SET PASSWORD FOR 'user-name-here'@'hostname' = PASSWORD('new-password');

For mysql database server version 5.7.6 or newer use the following syntax

ALTER USER 'user'@'hostname' IDENTIFIED BY 'newPass';

You can also use MySQL update command:

UPDATE mysql.user SET Password=PASSWORD('new-password-here') WHERE USER='user-name-here' AND Host='host-name-here';

In this example, change a password for a user called neo.

SET PASSWORD FOR 'neo'@'localhost' = PASSWORD('foobar');

OR

UPDATE mysql.user SET Password=PASSWORD('foobar') WHERE USER='tom' AND Host='localhost';

You will get some output like below:

Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Feel free to replace the values for “tom” (user), “localhost” (hostname), and “foobar” (password) as per your requirements. Finally, type the following command to reload privileges:

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

To exit from mysql> prompt, enter:

mysql> quit;

User or you can test new password using the following shell syntax:

# mysql -u neo -p
Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment