How To Reset MariaDB Root Password When You Forgot It

Reset MariaDB Root password

MariaDB is a database management system made to allow developers to run queries and manage their database and their data. It can be accessed through a different port on the network(which is usually 3306) and to get into it, one requires a strong password for it’s “root” username. While choosing a strong password, one can usually forget it because a strong password contains a combination of symbols, capital letters, small letters, and numbers. While forgetting password can be a big deal, we need to find a way to reset it. In this article, we’re going to learn how to reset the MariaDB root password.

What is MariaDB?

We’ve already defined what MariaDB means. Let’s see what is it actually, according to Wikipedia.

MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system, intended to remain free and open-source software under the GNU General Public License.

How To Reset MariaDB Root Password?

To begin with, resetting the password, we’ll have to log in to the server with root access. To do so, we’ll use the SSH client, Putty. Once we’re logging in, we’ll begin with resetting the password.

Step 1 – Stopping the MariaDB server

To reset the password, we’ll need to first stop the MariaDB server. To do so, we’ll use the below-mentioned command.

systemctl stop mariadb

If you’re not root, don’t forget to use “sudo” before the command.

Step 2 – Enabling Safe Mode & Logging into the server of the MariaDB server

To reset the password, we’ll need to first get into it. But without password, we can’t… Or, can we? Yes, we can. To do so, we’ll need to enable the MariaDB server’s safe mode. Use the following command to enter into safe mode.

mysqld_safe --skip-grant-tables &

So now we’re in safe mode. We’ll log in to the server. To do so, we’ll directly login without user password. Use the following command.

mysql -u root

Step 3- Resetting MariaDB root password

Root passwords are generally stored in the database named “mysql”. We’ll need to access the database. Use the following command to access the database.

USE mysql;

Before we begin resetting, we’ll need to flush the privileges to avoid errors like “insecure execution”. To do so, use the following command.


Now it’s time to reset the MariaDB root password. Use the below-mentioned command to do so.


Where “newpasswordhere” will be the new password you’d like to set for the username root. Since now we’ve reset the password, we’ll need to flush privileges again. Use the same command to do so.


We’ve flushed the privileges. We’re done and we’ll get out of the process. Use the below-mentioned command to do so.


Step 4 – Start MariaDB again normally with the new password

Before we start using the new password, we’ll need to kill safe mode. To do so, use the below-mentioned command.

killall mysqld

Now start the MariaDB normally.

systemctl start mariadb

You can now log in to your MariaDB with the new password. To log in, use this command.

mysql -u root -p

We’re done!

We did it! We’ve successfully changed/reset the password for MariaDB root user.

BE CAREFUL WITH THE USE OF MYSQL IN SAFEMODE! It’s basically like an open bank vault.

Get A New VPS to Begin Learning About Linux

If you’re a beginner in Linux computing, you’d probably be looking for ways to figure out new things. With Shadow Hosting’s VPS hosting solution, you can break things and make them again with one click OS reinstall interface for your VPS. Plus with our highly supportive staff, you’d regret why you didn’t found us earlier. All our VPS hosting solution are affordable and reasonable with high specs which can suit your needs.


If you’ve liked our article, we’d be glad that you show us your review in our comment box in the comment section below. Your thoughts and comments are very much appreciated to us.

Also, Read – How To Install LAMP Stack on CentOS 7

About Manal Shaikh 25 Articles
Manal Shaikh, the Founder of Shadow Networks International and CEO/Chairman of Shadow Hosting International. A cybersecurity analyst, network analyst and a web administrator.

Be the first to comment

Leave a Reply

Your email address will not be published.


CommentLuv badge