27/4/2022

MariaDb zonder root: en phpMyAdmin dan?

Filed under: — cybrarian @ 11:54 am

Korte versie:

Maak, als root, een phpmyadmin account met de nodige rechten:
CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'wachtwoord';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Ik begon van OpenSUSE 15.3 geïnstalleerde mysql (=MariaDb):
Server version: 10.5.15-MariaDB MariaDB package

Geen root login meer?

cybrarian@MijnMachine:~> mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Of toch?

cybrarian@MijnMachine:~> su
Password:
MijnMachine:/home/cybrarian # mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 10.5.15-MariaDB MariaDB package
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)]>

MariaDB [(none)]> select Host, User, Password from mysql.user;
+-----------+-------------+----------+
| Host      | User        | Password |
+-----------+-------------+----------+
| localhost | mariadb.sys |          |
| localhost | root        | invalid  |
| localhost | mysql       | invalid  |
| localhost |             |          |

Ik lees dat ze dit veranderd hebben in versie 10.4: https://mariadb.com/kb/en/authentication-from-mariadb-104/

Dit heeft het voordeel dat de root account vanaf installatie afgeschermd is, en dat je niet hals-over-kop eerst je root account moet gaan toe-zetten, zoals vroeger.

Het root account wordt automatisch gemaakt, en je kan het gebruiken als je root bent op je systeem, ofwel met sudo.

Het test account lijkt voor iedereen open te staan nu:

cybrarian@MijnMachine:~> mysql -u test
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.5.15-MariaDB MariaDB package
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 CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| @localhost     |
+----------------+
1 row in set (0.001 sec)
MariaDB [(none)]> select USER();        
+----------------+
| USER()         |
+----------------+
| test@localhost |
+----------------+
1 row in set (0.000 sec)
MariaDB [(none)]> exit
Bye

met een willekeurige naam:

cybrarian@MijnMachine:~> mysql -u joskevermeulen
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.5.15-MariaDB MariaDB package
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();        
+--------------------------+
| USER()                   |
+--------------------------+
| joskevermeulen@localhost |
+--------------------------+
1 row in set (0.001 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.001 sec)
MariaDB [(none)]> exit
Bye

Beveiligen
Het script na installatie blijft bestaan:

mysql_secure_installation

Het laat toe de root wachtwoord en login instellingen aan te passen, en eindigt met :


Remove test database and access to it? [Y/n]
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

en dan is:

MariaDB [(none)]> select Host, User, Password, plugin from mysql.user;
+-----------+-------------+----------+-----------------------+
| Host      | User        | Password | plugin                |
+-----------+-------------+----------+-----------------------+
| localhost | mariadb.sys |          | mysql_native_password |
| localhost | root        | invalid  | mysql_native_password |
| localhost | mysql       | invalid  | mysql_native_password |
+-----------+-------------+----------+-----------------------+
3 rows in set (0.002 sec)

phpMyAdmin
Als je hierboven *geen* root wachtwoord hebt gezet, dan zal phpMyAdmin niet werken met root.

From mysql 5.7 and mariadb 10.4 on, one cannot use ‘root’ login with default authentication method. One solution is to create a new admin user for the database just for phpMyAdmin.

Je moet dus ofwel

  • “root” weer gaan aktiveren en er een wachtwoord aan toekennen,
  • een gebruiker bijmaken voor phpMyAdmin, om zelf mee in te loggen via phpMyAdmin.

Aangezien ze root verwijderd hebben voor een reden, en dat ook zo in de volgende versies zal zijn, leer je er beter me leven. Kies een goede naam, waarmee je zelf weet waar hij voor dient (“phpmyadmin”?), of gebruik je eigen naam bv als je jezelf vertrouwt met root rechten; beperk eventueel tot localhost.

Log in als root (of je eigen gekozen beheerdersaccount).
ps: De “whoami” van mysql? check wie je nu bent met:
SELECT CURRENT_USER();

In de tabel mysql:
CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'VerzinZelf1Wachtwoord';

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]>CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'VerzinZelf1Wachtwoord';

MariaDB [mysql]> select Host, User, Password, plugin from mysql.user;

+-----------+-------------+-------------------------------------------+-----------------------+
| Host      | User        | Password                                  | plugin                |
+-----------+-------------+-------------------------------------------+-----------------------+
| localhost | mariadb.sys |                                           | mysql_native_password |
| localhost | root        | invalid                                   | mysql_native_password |
| localhost | mysql       | invalid                                   | mysql_native_password |
| localhost | phpmyadmin  | *60BE5F4C0B7FD3747C1845476CED1F220739403B | mysql_native_password |
+-----------+-------------+-------------------------------------------+-----------------------+

Helaas; ik kan nu wel inloggen in phpMyAdmin, maar ik zie geen tabellen, ik kan niets doen.
Nog rechten toekennen aan de nieuwe gebruiker:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.004 sec)

en de rechten herladen:

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

Hallo phpMyAdmin!

Powered by WordPress