How to reset MariaDb 10.4 root password on Linux


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

Related articles – Old articles:

How to change Mysql root password – November 6, 2016
How to reset MariaDb root password on Linux – August 20, 2017
How to reset MySQL root password on Linux – January 18, 2019

For Mariadb >= 10.4, our case : Mariadb 10.6 on Ubuntu 22.04

Step 1: stop mariadb service

service mariadb stop

Step 2:

sudo mysqld_safe --skip-networking &
mysql -u root
SET PASSWORD FOR 'root'@localhost = PASSWORD("new-password");
flush privileges;
exit;

result:

root@tutorialspots ~ # sudo mysqld_safe --skip-networking &
[1] 5881
root@tutorialspots ~ # 240226 16:22:31 mysqld_safe Logging to syslog.
240226 16:22:31 mysqld_safe Starting mariadbd 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 3
Server version: 10.6.16-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04

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)]> SET PASSWORD FOR 'root'@localhost = PASSWORD("new-password");
Query OK, 0 rows affected (0.023 sec)

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

MariaDB [(none)]> exit;
Bye

Step 3: stop mysqld_safe

root@tutorialspots ~ # ps aux|grep mysqld
root        5881  0.0  0.0  11504  5468 pts/2    S    16:22   0:00 sudo mysqld_safe --skip-networking
root        5882  0.0  0.0  11504   884 pts/0    Ss+  16:22   0:00 sudo mysqld_safe --skip-networking
root        5883  0.0  0.0   2892  1812 pts/0    S    16:22   0:00 /bin/sh /usr/bin/mysqld_safe --skip-networking
mysql       5981  0.0  0.1 1338288 83536 pts/0   Sl   16:22   0:00 /usr/sbin/mariadbd --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --skip-networking --skip-log-error --pid-file=/run/mysqld/mysqld.pid --socket=/run/mysqld/mysqld.sock
root        5982  0.0  0.0   9172  1488 pts/0    S    16:22   0:00 logger -t mysqld -p daemon error
root        6045  0.0  0.0   6480  2316 pts/2    S+   16:26   0:00 grep --color=auto mysqld
root@tutorialspots ~ # kill 5881
root@tutorialspots ~ # ps aux|grep mysqld
root        6057  0.0  0.0   6480  2432 pts/2    S+   16:27   0:00 grep --color=auto mysqld
[1]+  Done                    sudo mysqld_safe --skip-networking

Step 4: start Mariadb service

service mariadb start

Leave a Reply