简体   繁体   English

如何在docker容器中连接外部mysql服务器

[英]How to connect external mysql server in docker container

I built a Django app in a docker container. 我在docker容器中构建了一个Django应用程序。 And run it on a server with ip 192.168.1.13. 并使用ip 192.168.1.13在服务器上运行它。 And I set the Django settings.py to connect mysql server at 192.168.1.6. 我将Django settings.py设置为连接mysql服务器192.168.1.6。 It is an external independent server. 它是一个外部独立服务器。 But when I run the container, it always say access denied for user xxx@192.168.1.13. 但是当我运行容器时,它总是说用户xxx@192.168.1.13拒绝访问。 How can Django connect to the docker host ip but not the defined server ip? Django如何连接到docker主机ip而不是定义的服务器ip?

Any body can help me to solve this problem? 任何人都可以帮我解决这个问题吗? Many thanks. 非常感谢。

There are two server. 有两个服务器。

Server A is 192.168.1.13. 服务器A是192.168.1.13。 There is a django docker container running on it. 有一个django docker容器在它上面运行。

Server B is 192.168.1.6. 服务器B是192.168.1.6。 It is a mysql server. 它是一个mysql服务器。

And I want django container to connect server B. But it reported can't connect to its host server. 我希望django容器连接服务器B.但它报告无法连接到其主机服务器。

It looks like you granted access to your user accessing only through the localhost. 看起来您只授予通过localhost访问的用户访问权限。 Try the following on your MySQL server: 在MySQL服务器上尝试以下操作:

GRANT ALL PRIVILEGES ON * . * TO 'xxx'@'192.168.1.13';

Please note that the IP address after the @ above refers to the address the MySQL client is connecting from (your Django container), not the address of the MySQL server. 请注意, @ above之后的IP地址是指MySQL客户端连接的地址(您的Django容器),而不是MySQL服务器的地址。

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

相关问题 在docker中连接到mysql服务器 - connect to mysql server in docker docker容器中的jupyterhub无法连接到外部目录 - jupyterhub in docker container not able to connect to external directory 如何从Docker容器中的python脚本连接到localhost上的mysql数据库 - How to connect to a mysql database on localhost from a python script in a docker container 如何连接rabbitMQ docker容器? - How to connect to the rabbitMQ docker container? 使用Python连接到Docker容器中的MySQL - Connect to MySQL in Docker container using Python 无法使用 Dockerfile 连接到 docker 容器(python 服务器) - Can not connect to docker container(python server) with Dockerfile Mariadb docker容器无法使用Python连接到主机上的MySQL服务器(111连接被拒绝) - Mariadb docker container Can't connect to MySQL server on host (111 Connection refused) with Python Docker + Airflow - 无法从 Z05B6053C41A21340AFD6FC3B234Z 容器连接到主机上的 MySQL - Docker + Airflow - Unable to connect to MySQL on host from docker container 如何将Flask应用程序docker容器连接到本地mongoDB(不是docker容器) - How to connect Flask app docker container to local mongoDB (not docker container) 如何通过运行带有URL的docker容器来连接docker容器中的python应用 - how to connect python app in docker container with running docker container with url
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM