How to reset MariaDb root password on Linux


You forgot or you unknow your root MYSQL password! How to reset MariaDb root password on Linux?

Step 1: stop MariaDb

service mysql stop

or in some cases:

service mariadb stop

Result:

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

Step 2:

sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root
use mysql;
update user set password=PASSWORD("new-password") where User='root';
flush privileges;
exit;

Result:

[root@tutorialspots ~]# sudo mysqld_safe --skip-grant-tables --skip-network
ing &
[1] 158022
[root@tutorialspots ~]# 170820 13:41:20 mysqld_safe Logging to '/var/log/my
sqld.log'.
170820 13:41:20 mysqld_safe Starting mysqld daemon with databases from /var/lib/
mysql
mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.0.26-MariaDB MariaDB Server

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

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

MariaDB [(none)]> use mysql;
No connection. Trying to reconnect...
Connection id:    3
Current database: *** NONE ***

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("new-password") where User='r
oot';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

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

MariaDB [mysql]> exit;
Bye

Step 3: stop and start Mariadb service

[root@tutorialspots ~]# service mysql stop
Shutting down MySQL.. SUCCESS!
[root@tutorialspots ~]# service mysql start
Starting MySQL. SUCCESS!

or in some cases:

service mariadb stop
service mariadb start

Note: You can’t use command service mysql restart

Leave a Reply