简体   繁体   English

在主机模式下从 docker 容器连接到 MySQL 主机数据库不起作用

[英]Connecting to MySQL host DB from docker containers in host mode not work

I try connect my mysql host DB from docker container by using host mode and I get the error:我尝试使用主机模式从 docker 容器连接我的 mysql 主机数据库,但出现错误:

docker run --rm -it --network=host mysql mysql -h 127.0.0.1 -utestuser -p

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)

The base of my work is stackoverflow-answer https://stackoverflow.com/a/24326540/1514029我的工作基础是 stackoverflow-answer https://stackoverflow.com/a/24326540/1514029

My host mysql version is 8.0.25.我的主机 mysql 版本是 8.0.25。

I tried in my.cnf bind-address = 0.0.0.0 and bind-address = 172.17.42.1我在 my.cnf 中尝试了 bind-address = 0.0.0.0 和 bind-address = 172.17.42.1

Every binding have the same problem.每个绑定都有相同的问题。

I grant the testuser user access to 127.0.0.1 by statements我通过语句授予 testuser 用户对 127.0.0.1 的访问权限

CREATE USER testuser@127.0.0.1 IDENTIFIED BY 'blah'
grant all privileges on *.* to testuser@127.0.0.1 with grant option

On docker bridge mode my connection work fine only on docker host mode it fails!在 docker 桥接模式下,我的连接只能在 docker 主机模式下正常工作,但它失败了!

It must be a network problem??应该是网络问题??

you can use:您可以使用:
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.25 docker 运行 --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM