How to Reset MariaDB root Password in Linux

Channel: Linux
Abstract: Step 2 – Change Password After starting MariaDB in safe more connect to MariaDB with root user and without any password. After that run following comm

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.

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

Step 1 – Start 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 – Change 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

> use mysql; > UPDATE user SET authentication_string = password("SecreT") where User='root'; > FLUSH PRIVILEGES;123> use mysql;> UPDATE user SET authentication_string = password("SecreT") where User='root';> FLUSH PRIVILEGES;

Step 3 – Stop 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 – Login 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)]> 

Ref From: tecadmin

Related articles