Lost your MariaDB root password? Well, you’re in luck because this brief tutorial is going to show you how get into the database server and create a new root password.

When you forget the root password for MariaDB database server, you can’t just unlock or recover it, you must create a new and different one. To do this you need root privileges on the server you’re running MariaDB database server on. Then you need to use a backdoor trick that most people use to the reset forgotten root password for MySQL or MariaDB database server.

So, if you’ve forgotten your password to sign on MariaDB server, continue below.

This first thing you need to do is stop the database server. Obviously your site will be down, but this is the only way to access the backdoor of the server to reset the password. To stop or shutdown MariaDB on CentOS 7, run the commands below.

sudo systemctl stop mariadb.service

 

On Ubuntu run the commands below

sudo service mariadb stop

 

Next, you need to start MariaDB with unrestricted access so you wouldn’t need password to sign on as the root user. This starts the database server in an insecure manner keeping it wide open to anyone.

Because the database is left wide open, you should safeguard against someone logging into the database remotely. This could happen, so add the –skip-networking option to the commands.

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

 

Now that the database is started, you can now logon to it without passwords. Run the commands below to sign on to the database without prompting for password.

mysql -u root

 

Once you’re logged-on, change to the mysql database. This database comes with all MySQL and MariaDB servers. It’s store encrypted credentials and privileges for the root user.

To change to the mysql database, run the commands below.

use mysql;

 

Next, run the commands below to change the root password

update user set password=PASSWORD("new-password") where User='root';

Remember to replace new-password with the root password and press Enter.

Then run the commands below to flush or reset the privileges table.

flush privileges;

Exit.

 

Now that the root password is changed, you should now be able to stop/start MariaDB server normally and and logon as the root user using the new password you created above.

You can stop, then start the server using the commands below

To stop the database, run the commands below.

sudo systemctl stop mariadb.service

To start, run the commands below

sudo systemctl start mariadb.service

 

Then logon as the root user with the new password using the commands below. W

mysql -u root -p

 

That’s it!  This is how you reset or re-created forgotten root password for MariaDB database server.

 

 

 

Frequently Asked Questions

How can I reset a forgotten MariaDB root password on CentOS 7?

To reset a forgotten MariaDB root password on CentOS 7, you need to have root privileges on the server. Follow the steps in the article to stop the database server, start MariaDB with unrestricted access, log on without a password, and change the root password.

What should I do if I forget my MariaDB root password?

If you forget your MariaDB root password, you must create a new one. Follow the steps outlined in the article to reset the password using a backdoor trick that allows you to access the database server without a password.

How do I stop MariaDB on CentOS 7?

To stop MariaDB on CentOS 7, run the command 'sudo systemctl stop mariadb.service'. On Ubuntu, use 'sudo service mariadb stop'. Stopping the server is necessary to reset the root password.

Can I start MariaDB with unrestricted access on CentOS 7?

Yes, you can start MariaDB with unrestricted access on CentOS 7 by using the command 'sudo mysqld_safe --skip-grant-tables --skip-networking'. This allows you to log on to the database without a password.

What is the mysql database used for in MariaDB?

The mysql database in MariaDB stores encrypted credentials and privileges for the root user. It is essential for managing user access and permissions within the database server.

How do I log on to MariaDB without a password?

To log on to MariaDB without a password, run the command 'mysql -u root'. This allows you to access the database server without being prompted for a password.

Why is it important to safeguard against remote logins when starting MariaDB with unrestricted access?

It is important to safeguard against remote logins when starting MariaDB with unrestricted access to prevent unauthorized access to the database. Adding the --skip-networking option helps mitigate the risk of someone logging in remotely.

What precautions should I take after resetting the MariaDB root password?

After resetting the MariaDB root password, ensure to secure the server by setting a strong password, limiting remote access, and implementing other security measures to protect the database from unauthorized access.