MySQL MariaDB

How to Change MariaDB User Password

“MariaDB is an open-source, relational database management system (RDBMS). The MariaDB client allows you to add new users and grant them different degrees of privileges with ease.

To learn more about MariaDB, check this out:

https://mariadb.org/

This tutorial will explain to you how to change the password for a MariaDB user. We will perform the task using the Linux command line with the help of a few easy-to-follow commands. We have divided the guide into two parts. In part 1, we will change the MariaDB user password, and in part 2, we will change the MariaDB root password.”

Without any further ado, let’s get started!

Guide

Part 1: Change MariaDB User Password

In this section, you will see how to change MariaDB’s normal user password.

First, open the command line and log into MariaDB as the root user using this command:

mariadb -u root -p

The next step is to switch to the mysql database by executing the following command:

MariaDB [(none)]> use mysql;

Using the following syntax, switch the user’s password:

MariaDB [mysql]> ALTER USER 'user'@'localhost' IDENTIFIED BY 'new_password';

Make sure to replace the user and password with your user and password.

Now refresh the privileges by using the following command:

MariaDB [mysql]> FLUSH PRIVILEGES;

Now exit the database:

MariaDB [mysql]> exit

Let’s now check if the changes we made are working by trying to re-login the database with the new password:

mariadb -u username -p

Part 2: Change MariaDB Root Password

In this section, you will see how to change the MariaDB root password.

Start with stopping the running MariaDB database instance. Do that by issuing the following command:

sudo systemctl stop mariadb

Next, start the database again with –the skip-grant-tables option, which will let us connect with the DB without having to provide a password. This can be done by executing the below-mentioned command:

sudo mysqld_safe --skip-grant-tables --skip-networking &

Now you can log in as root without giving the root password with this command:

mariadb -u root

Refresh the privileges with the FLUSH command like this:

MariaDB [(none)]> FLUSH PRIVILEGES;

After that, change the root password using the command mentioned below:

MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password_here';

Make sure to replace the word password with your password.

Next, exit the database like this:

MariaDB [(none)]> exit

Once we have exited the DB, we will terminate the current mysqld process with this command:

sudo pkill mysqld

Next, start your MariaDB server backup by executing the following command:

sudo systemctl start mariadb

The last step is to verify if the root password we just changed is working or not. It can be done by trying to log in to MariaDB using the new root password.

mariadb -u root -p

Conclusion

In today’s tutorial, we saw in detail how to change the password for a user in MariaDB. First, we explored how to change a normal user password. Next, we saw how to change the root user password.

I hope you liked the tutorial.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.