3

I built a Django app in a docker container. And run it on a server with ip 192.168.1.13. And I set the Django settings.py to connect mysql server at 192.168.1.6. It is an external independent server. But when I run the container, it always say access denied for user [email protected]. How can Django connect to the docker host ip but not the defined server ip?

Any body can help me to solve this problem? Many thanks.

There are two server.

Server A is 192.168.1.13. There is a django docker container running on it.

Server B is 192.168.1.6. It is a mysql server.

And I want django container to connect server B. But it reported can't connect to its host server.

1 Answer 1

1

It looks like you granted access to your user accessing only through the localhost. Try the following on your MySQL server:

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your reply. But I don't think your suggestion will work. Because 192.168.1.13 is my docker host. It is not the mysql server indeed. MySQL server IP is 192.168.1.6. I set it in the settings.py, but django instance try to connect 192.168.1.13 instead. That is my problem.
The IP address specified in the answer refers to the host the user is connecting from, not the one it connects to. Have you tested my command?
Thank you. I am so stupid. I misunderstood your suggestion. Your answer is correct. My problem is resolved. Thank you again.
Can you use wild cards for the IP? Say I want everyone on 192.168.*.* to be able to connect.
Yes, you use a % sign as a wildcard. like: user_name@'192.168.%'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.