How To Change User Password In MySQL Server 5.x On CentOS

If you’re not aware of how to change user password in MySQL server, so you can run the below commands to change it very easily but commands vary from version to version. MySQL can alter the user password using the command line.

Check Out: Solve MySQL Too Many Connections Error

How To Change User Password In MySQL Server 5.x:

Log in the database server using mysql -u root -p

Now switch to MySQL database, 

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

If these commands do not work for you, So you may run the below commands.

1. SET PASSWORD FOR 'user'@'localhost' = PASSWORD('MyNewPass');

Or you can also use this command to update the password of a user. 

2. UPDATE mysql.user SET Password=PASSWORD(‘newpass’) WHERE User=’user’ AND Host=’host’;

Check Out:  Enable MySQL General Query Log

There’re other ways to change the user password. let’s explore them. With a for user clause, run the below command but user must exist,

SET PASSWORD FOR 'user'@'localhost' = 'auth_string'

Without a user clause, run the below command for the current user,

SET PASSWORD = 'auth_string'; 

you can change the password of any client which connects the server using user and password. 

Check Out: Could Not Find Driver With Class Name: com.mysql.jdbc

To see which account the server authenticated you,

select current_user();

Then run the command to set the password,

SET PASSWORD FOR 'user'@'' = 'auth_string';

You’re done mysql alter user

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment