Docker容器内部Python连接宿主机MySQL 1、防火墙不对外开放3306端口的情况下,确保开放docker容器ip的入站访问。 2、容器内连接地址填写容器网管,例如:`172.17.0.1` 3、若返回错误提示:`mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported`,说明`mysql.connector`插件装错了,应该安装`mysql-connector-python`: pip install mysql-connector-python