How to Reset MariaDB root Password in Linux CentOS/RHEL

Did you forget MariaDB root password ? If yes, do not worry we have an easy way to reset database root password on Linux server. To reset password you will need root privilege of Linux server. Firstly you will need to stop database service after stopping service your database will stop working but do not worry it will take maximum 5 minute to complete.

Stop MariaDB service [root@MariaDB ~]# service mysql stop
Shutting down MySQL. [ OK ]

Start MariaDB in Safe Mode
Start MariaDB in safe mode with ‘skip-grant-tables’ option. Grant tables store the passwords, so using this option you can login to MariaDB without password
[root@MariaDB ~]# mysqld_safe –skip-grant-tables &
151209 17:44:05 mysqld_safe Logging to ‘/var/lib/mysql/MariaDB.linux.in.err’.
151209 17:44:05 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

Login in Database using below command
[root@MariaDB ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.46-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

Once you logged in DB, use following SQL to reset MariaDB password
MariaDB [(none)]>use mysql;
MariaDB [mysql]> UPDATE user SET password=PASSWORD(“new_password“) WHERE User=’root’;
Note: You will need to put password place of “new_password“.

Flush database privileges and exit
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> quit

Now Restart MardiaDB database
[root@MariaDB ~]# service mysql restart

Finally Login in Database with changed password
[root@MariaDB ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.46-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
Share on Google Plus

About Penguin Technology

I am a passionate cloud and DevOps professional specializing in Linux and open-source solutions. Through this blog, I share my knowledge and experience with the community, offering tips and insights on cloud technologies and DevOps practices.
    Blogger Comment

0 comments:

Post a Comment