How you Reset a Forgotten Root Password of MariaDB On CentOS 7.x Server

There are some easy step to Reset a Forgotten Root Password of  MariaDB On CentOS 7 Server

1- Login as user root in your Linux system and stop MariaDB daemon with the following command

[root@localhost ~]#  /etc/rc.d/init.d/mysql stop
Shutting down MySQL…… SUCCESS!

[root@localhost ~]#

or

[root@localhost ~]# service mysql stop
Shutting down MySQL. SUCCESS!
[root@localhost ~]#

2- Start MariaDB in safe mode with ‘skip-grant-tables’ option. Grant tables store the passwords of the users which stores in the mysql Database , so using this option you can login MariaDB without password.

[root@localhost ~]# mysqld_safe –skip-grant-tables &
[1] 16452
[root@localhost ~]# 150910 15:18:37 mysqld_safe Logging to ‘/var/lib/mysql/localhost.localdomain.err’.
150910 15:18:37 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@localhost ~]#

3- Now, you are able to login MariaDB without a password 

[root@localhost ~]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.45-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.

MariaDB [(none)]>

4- Now you use “mysql” Database and run following query to reset fogotten MariaDB root passwod.

 

 note: Replace ‘system@123’ with your real password which you want to change.

MariaDB [mysql]> use mysql;
Database changed
MariaDB [mysql]>

Database changed
MariaDB [mysql]> update user set password=PASSWORD(“system@123”) where user=’root’;
Query OK, 0 rows affected (0.12 sec)
Rows matched: 4  Changed: 0  Warnings: 0

MariaDB [mysql]>


 
5- Now, flush the privileges and exit from the MariaDB server.

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> quit
Bye
[root@localhost ~]#

6- Now Restart MariaDB deamon with the following command and enjoy with new Password.

[root@localhost ~]# service mysql restart
Shutting down MySQL..150910 15:42:49 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended
SUCCESS!
Starting MySQL… SUCCESS!
[1]+  Done                    mysqld_safe –skip-grant-tables

[root@localhost ~]#


[root@localhost ~]# mysql -uroot -psystem@123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.45-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.

MariaDB [(none)]>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s