我正在尝试将一个docker容器与mariadb和node.js镜像配合使用。该容器将使用现有的数据库在/home/mysql
中。然而,当容器启动时,我在node.js中遇到了"连接失败"的错误:
Error: ER_HOST_NOT_PRIVILEGED:
Host '172.18.0.5' is not allowed to connect to this MariaDB server
这是我的docker-compose.yml文件:
version: '3'
services:
mariadb:
image: mariadb
restart: always
volumes:
- /home/mysql:/var/lib/mysql
user: "mysql"
ports:
- "3306:3306"
watch:
build: .
restart: always
links:
- mariadb:mysql
environment:
- DOCKER_IP=172.18.0.2
depends_on: ['mariadb']
ports:
- "3000:3000"
阅读了这个线程后,我发现mysql实际上正在运行,但它无法让其他服务连接:
以下是我已经检查过的一些步骤。正如您所看到的,我可以登录到mysql实例中:
$ docker exec -it 552aae9ea09c bash
mysql@552aae9ea09c:/$ mysql -u root -p
Enter password: *******
MariaDB [(none)]> SELECT host, user FROM mysql.user;
+-------------+------------------+
| host | user |
+-------------+------------------+
| 127.0.0.1 | root |
| ::1 | root |
| someusername| |
| someusername| root |
| localhost | |
| localhost | dbusername |
| localhost | databasename |
| localhost | root |
+-------------+------------------+
8 rows in set (0.00 sec)
mysql@552aae9ea09c:/$ mysqld --verbose --help | grep bind-address
2017-11-13 17:35:40 139825857279872 [Note] Plugin 'FEEDBACK' is disabled.
--bind-address=name IP address to bind to.
bind-address (No default value)
需要注意的一点是,尽管在yml文件中明确将用户设置为mysql
,但在/home/mysql目录下的这三个文件:ib_logfile0
、ib_logfile1
和ib_buffer_pool
仍然属于systemd-journal-remote
组,我怀疑这与连接失败有关。(参考)
ER_HOST_NOT_PRIVILEGED:主机'172.16.254.6'不被允许连接到此MySQL服务器
。你有什么其他的想法吗? - Gleichmut