As mentioned below there is a glitch in 1.5.8 on Debian 10 as well. I just spun up a test VM and did a quick recovery as the steps might vary between different systems and versions. This should work on Debian 10 with MariaDB 10.3.22 - run as root:
systemctl stop mariadb.service
mysqld_safe --skip-grant-tables &
mysql -u root
Now from here we are in the mysql shell and can try to change the password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.22-MariaDB-0+deb10u1 Debian 10
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)]> select user,password,host,plugin from mysql.user;
+------+-------------------------------------------+-----------+-----------------------+
| user | password | host | plugin |
+------+-------------------------------------------+-----------+-----------------------+
| root | *B9179FF9CF31E6DDF1DCEA4E656BCB4C5CA71943 | localhost | mysql_native_password |
+------+-------------------------------------------+-----------+-----------------------+
1 row in set (0.002 sec)
MariaDB [(none)]> update mysql.user set password=PASSWORD("newpassword") where User='root';
Query OK, 1 row affected (0.001 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> update mysql.user set authentication_string=PASSWORD("newpassword") where User='root';
Query OK, 1 row affected (0.002 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> update mysql.user set plugin='mysql_native_password' where User='root';
Query OK, 0 rows affected (0.002 sec)
Rows matched: 1 Changed: 0 Warnings: 0
MariaDB [(none)]>
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.009 sec)
MariaDB [(none)]> quit
Bye
Ok, password is set! Now let’s restart the DB and test connecting as root:
killall -15 mysqld
systemctl start mariadb.service
mysql -u root -p
Maybe even re-set the password again using the proper tools now that you have access again because messing with the user table is not that great but as far as I know it’s the only way on this version.
mysqladmin -u root -p password
Enter password:
New password:
Confirm new password: