If you come across a situation where you do not remember to master password (root password) of Maria DB then following simple steps will be helpful to reset the root password.
- First stop MariaDB Server.
# systemctl stop mariadb
- Edit /etc/my.cnf file and add following line (skip-grant-tables) in [mysqld] section as given below.
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-grant-tables
- Now start MariaDB. It will open without any password.
# systemctl start mariadb
- Login to MariaDB as below.
# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 96823 Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
- Now set mysql root password using following commands.
MariaDB [(none)]> use mysql ; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [mysql]> update user set password=password('123') where user='root' ; Query OK, 0 rows affected (0.00 sec) Rows matched: 4 Changed: 0 Warnings: 0 MariaDB [mysql]> flush privileges ; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]> quit ; #
- Now edit /etc/my.cnf file again and remove line (skip-grant-tables) in [mysqld] section.
- Now it’s time to restart MariaDB server again.
# systemctl restart mariadb
You have done it !