Skip to content

How to Reset MariaDB root Password in Linux

Reset MariaDB root Password. How to Reset MariaDB root Password in Linux systems. Recover MariaDB root password with few easy steps.

Steps
4
Category
Databases
Covers
MariaDB, MySQL
On this page 4 steps

Have you forgotten MariaDB root password? You don’t know how to recover it. Not to worry, this tutorial will help you to reset MariaDB root password on Linux system.

Reset MariaDB root Password

Let’s follow this step by step tutorial to reset MariaDB root password on your Linux systems.

Step 1 of 4Start MariaDB in Safe Mode

First of all, you need to stop MariaDB service on your system. You can do this using the following command.

sudo systemctl stop mysql.service

Now start your MariaDB service in safe mode using skip grant and run this command in the background.

mysqld_safe --skip-grant-tables &

Step 2 of 4Change Password

After starting MariaDB in safe more connect to MariaDB with root user and without any password. After that run following command to change the root user password.

mysql -u root

Step 3 of 4Stop and Start MariaDB

After successfully changing the password, stop the MariaDB service and start it again in normal mode using following commands.

sudo systemctl stop mysql.service
sudo systemctl start mysql.service

Step 4 of 4Login with New Password

You have now new root user password for your MariaDB instance. Login to MariaDB instance to verify the new password.

mysql -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

5 Comments

  1. I was recently installing mysql in Ubuntu Bionic Beaver and the command ‘UPDATE User SET password…’ does not apply here. Instead, you have to do

    UPDATE User SET authentication_string = password(“Mypassword”) where User=’root’;

    for the password to be updated.

    Thanks for the great post.

  2. One issue. is you have to be logged in as a system root user for all these commands, if not, then use sudo and then the command. i.e. sudo mysqld_safe –skip-grant-tables &

    If you are not logged in as a root user, then you will get many issues and not be able to reset your password. Also I would avoid using # or @ in your passwords.

Leave a Reply

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


Back to top