MariaDB – ERROR 1130 (HY000) Not Allowed to Connect to Server: Granting Permission Issue

mariadbmariadb-10.3

I am trying to connect to mariadb running different container.Getting below error
$ mysql -u root -h test-mysql –port 3306

ERROR 1130 (HY000): Host 'test_1_73f6dacd1d23.test_bluenet' is not allowed to connect to this MariaDB server

Mariadb Server:
I tried the following
MariaDB [(none)]> SELECT host, user FROM mysql.user;

+--------------+------+
| host         | user |
+--------------+------+
| 00a7a6a8d0af |      |
| 00a7a6a8d0af | root |
| 127.0.0.1    | root |
| ::1          | root |
| localhost    |      |
| localhost    | root |
+--------------+------+
6 rows in set (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON . TO 'root'@'%';

ERROR 1133 (28000): Can't find any matching row in the user table

Best Answer

The GRANT statement doesn't work because the user@host combination root@'%' doesn't exist (yet). You can create it and then re-run the GRANT:

CREATE USER root@'%' IDENTIFIED BY 'your_secret_password_here'; 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

The WITH GRANT OPTION part gives the user the power to GRANT privileges to other users.

Note that in order to be able to connect from the other container, you may also have to remove or comment out any restrictions in your configuration (i.e. files like /etc/my.cnf, /etc/my.cnf.d/server.cnf, /etc/mysql/*.cnf) such as any bind-address settings:

bind-address  = 127.0.0.1

Comment out with a '#':

# bind-address  = 127.0.0.1

... and then restart MariaDB.