How to Change MySQL User Password
In this instructional exercise, we will tell you the best way to change MySQL client secret word. The guidelines should work with any cutting edge Linux dispersion, for example, Ubuntu 18.04 and CentOS 7.
Prerequisites
Contingent upon the MySQL or MariaDB worker rendition you are running on your framework, you should utilize various orders to change the client secret word.
You can discover your information base worker rendition by giving the accompanying order:
mysql --version
On the off chance that you have MySQL introduced in your framework the yield will look something like this:
mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper
Or then again yield like this for MariaDB:
mysql Ver 15.1 Distrib 10.1.33-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Make certain to make note of which rendition of MySQL or MariaDB you're running. In the event that you need to get a rundown of all MySQL client accounts please check this guide.
How to Change MySQL User Password
Play out the means underneath to change the MySQL client secret word:
1. Login to the MySQL shell as root
Access the MySQL shell by composing the accompanying order and enter your MySQL root client secret phrase when provoked:
mysql -u root -p
On the off chance that you haven't set a secret word for the MySQL root client you can sign in with sudo mysql.
2. Set the MySQL user password
Type the accompanying orders on the off chance that you have MySQL 5.7.6 and later or MariaDB 10.1.20 and later:
ALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
FLUSH PRIVILEGES;
In the event that ALTER USER articulation doesn't work for you, you can change the client table straightforwardly:
UPDATE mysql.user SET authentication_string = PASSWORD('NEW_USER_PASSWORD')
WHERE User = 'user-name' AND Host = 'localhost';
FLUSH PRIVILEGES;
Type the accompanying orders in the event that you have MySQL 5.7.5 and prior or MariaDB 10.1.20 and prior:
SET PASSWORD FOR 'user-name'@'localhost' = PASSWORD('NEW_USER_PASSWORD');
FLUSH PRIVILEGES;
Ensure you change client name with the name of the client you need to change the secret phrase to. On the off chance that the client is interfacing with the MySQL worker from another host, change localhost with the distant hostname or IP Address.
In the two cases if all works out positively, you will see the accompanying yield:
Query OK, 0 rows affected (0.00 sec)
Log out from the MySQL brief by executing:
quit;
3. Verify the new password
To confirm that the new secret word has been applied effectively type:
mysql -u user-name -h localhost -p
You will be provoked to enter the new client secret word. Enter it, and you will be signed into your MySQL worker.
Conclusion
In this instructional exercise, you have figured out how to change MySQL or MariaDB client secret key. Ensure the new secret phrase is solid and secure and keep it in a protected spot.
To become familiar with how to utilize the MySQL shell to perform different organization activities you can check our guide about how to oversee MySQL client records and information bases .
Don't hesitate to leave a remark in the event that you have any inquiries.