[英]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.