Zum Hauptmenü

Root-Login in MariaDB nach Debian-Upgrade nicht mehr möglich

Jörg Kruse

Nach einem Upgrade eines älteren Entwicklungssystems von Debian Bookworm auf Debian Trixie funktionierte der Login des Users root in MariaDB nicht mehr. Ein systemctl status mariadb gab folgende Fehler aus:

Reading datadir from the MariaDB server failed. Got the following error when executing the 'mysql' command line client
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
FATAL ERROR: Upgrade failed

Schon seit einigen Debian-Versionen erfolgt die Authentifizierung des MariaDB-Users root nicht mehr über eine Passwortabfrage, sondern über einen Unix-Socket. Der Socket war auch aktiv:

Version: '11.8.2-MariaDB-1 from Debian' socket: '/run/mysqld/mysqld.sock' port: 3306 --

Der Linux-Root sollte sich demnach ohne Passwort als MariaDB-User root einloggen können. Genau das funktionierte hier nicht mehr:


$ su -
Password:
# mysql
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Andere User dagegen können sich problemlos per Passwort einloggen.

Vor dem Debian-Upgrade hatte ich, wie in den Release-Notes empfohlen, den MariaDB-Server gestoppt. Trotzdem schien hier irgendwas schief gelaufen zu sein. Um die Situation als root zu begutachten und ggf. zu bereinigen, startete ich MariaDB über mariadbd-safe mit der Option –skip-grant-tables. Danach war ein passwortloser Login mit dem mysql Client möglich:


# systemctl stop mariadb.service
# mariadbd-safe --skip-grant-tables &
[1] 171235
250902 15:22:55 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql
# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 11.8.2-MariaDB-1 from Debian -- Please help get to 10k stars at https://github.com/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.

Eine Abfrage nach dem Authentifizierungs-Plugin von root@localhost ergab, dass wie bisher das Plugin unix_socket genutzt wird:


MariaDB [(none)]> FLUSH PRIVILEGES;
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]> SELECT Host, User, plugin FROM user WHERE User = 'root';
+-----------+------+-------------+
| Host      | User | plugin      |
+-----------+------+-------------+
| localhost | root | unix_socket |
+-----------+------+-------------+
1 row in set (0.003 sec)

Das FLUSH PRIVILEGES am Anfang ist notwendig, um folgende Änderungen vornehmen zu können. Eine Änderung auf das Plugin mysql_native_password wäre möglich (wobei dann unbedingt auch ein Passwort für root gesetzt werden muss!). Aber ich wollte die Authentifizierungsmethode unix_socket beibehalten. Mein Reparaturversuch sah dann so aus, dass ich die Authentifizierungsmethode zweimal änderte:


MariaDB [mysql]> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password;
MariaDB [mysql]> FLUSH PRIVILEGES;
MariaDB [mysql]> ALTER USER 'root'@'localhost' IDENTIFIED WITH unix_socket;
MariaDB [mysql]> FLUSH PRIVILEGES;
MariaDB [mysql]> quit

Nachdem die Instanz von mariadbd-safe beendet und der MariaDB-Server neu gestartet wurde, konnte root sich wieder in MariaDB einloggen – der Reparaturversuch war anscheinend geglückt:


# pkill mariadb
# systemctl start mariadb
# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 11.8.2-MariaDB-1 from Debian -- Please help get to 10k stars at https://github.com/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.

Und auch systemctl status mariadb vermeldete statt der vorherigen Fehler den bedarfsweisen Upgrade der Tabellen:

Upgrading MariaDB tables if necessary.

Kommentar schreiben

Erlaubte HTML-Tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Kommentare werden erst nach Freischaltung veröffentlicht