How to Change MySQL / MariaDB User Passwords on Ubuntu 16.04 | 18.04

After installing MySQL or MariaDB server, one can create and reset user passwords easily via its command terminal or shell.. For example, if you wish to reset or change MySQL / MariaDB root password or another user, the steps below will help you do that…

This brief tutorial shows students and new users how to easily change MySQL or MariaDB user password via its shell terminal…

This tutorial is not about retrieving forgetting user’s passwords… You must already know the current password for the root account for this to work… You won’t be able to reset user passwords without first knowing the root password to logon to MySQL or MariaDB server…When you’re ready to reset user passwords, follow the steps below:

Base on the MySQL / MariaDB server you are running, you will need to use different commands to change user passwords…

Step 1: Finding MySQL / MariaDB Version

Find out the version of MySQL or MariaDB database server you’re running by running the commands below:

mysql --version

When you run the commands above, it will show you the version of MySQL or MariaDB installed…

MySQL
mysql Ver 14.14 Distrib 5.7.22
MariaDB
mysql Ver 15.1 Distrib 10.1.33-MariaDB

Take notes of the version of either database you’re running… You will need it below.

Step 2: Reset User Password

Now that you know the version of the database server you running, run the commands below to logon to the database…

sudo mysql -u root -p

Type in the root password and logon..

Then type the following commands if you are running MySQL 5.7.6 and later or MariaDB 10.1.20 and later to reset or change a user password:

ALTER USER 'username'@'localhost' IDENTIFIED BY 'NEWPASSWORD';
FLUSH PRIVILEGES;

Replace usernmae and NEWPASSWORD with the username and new password you want to use for the user…

If the ALTER statement doesn’t work, you can run the commands below to change it…

UPDATE mysql.user SET authentication_string = PASSWORD('NEWPASSWORD')
WHERE User = 'username' AND Host = 'localhost';
FLUSH PRIVILEGES;
exit;

Exit and that should do it.

For MySQL 5.7.5 and earlier or MariaDB 10.1.20 and earlier, use the commands below to change the user password

SET PASSWORD FOR 'username'@'localhost' = PASSWORD('NEWPASSWORD');
FLUSH PRIVILEGES;
exit;

Close out and you’re done.

If the commands were executed successfully, you should get a Query OK responses..

That should do it for you…

Congratulations! You have successfully change MySQL / MariaDB user password… This should apply to all modern Linux systems running the databases mentioned above…

You may also like the post below:

How to Set Timezone on Ubuntu 16.04 / 18.04 Desktops / Servers

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.