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 xxx#192.168.1.13. 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.
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.
Related
The project is a django web app, packed on docker containers. For some reason, I cannot run the server and launch it.
when I run "manage.py runserver", this error occurs:
File "C:\Users\andre\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: connection to server at "158.160.17.21", port 5432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?
What do you think can be done with it? Thank you.
The first line of your error tells me that you're using a locally installed copy of psycopg2, a Python client library for PostgreSQL, to connect to the database. This is happening behind the scenes when Django needs to make that connection, but it's interesting that it's installed locally, rather than in a docker container, given you said your Django webapp is running in Docker.
The third line of your error is very simple: it tells you that
the programme is expecting Postgres to be served on a machine with the IP address 158.160.17.21 on port 5432 (the default port for Postgres)
it isn't there
Now, this IP address is not a default and doesn't refer to your own machine, so it must be something you've provided. An IP lookup suggests it's in Venezuela (does that sound right to you?). Perhaps you are expecting Postgres to be served on a third party machine; if so, you'll need to check that you have the right IP address and that Postgres is being served there.
Otherwise, you'll need to reconfigure Django to seek Postgres elsewhere.
Open Task Manager > Services tab > Right-Click on Mongo > Start.
Now go re-run the server again.
I have a discord.py bot and I host it on Google Cloud RDP (windows). I was working and testing PostgreSQL database on my local computer and it was working like charm now when I tried to use the same code and same connection method on my RDP, I got an error.
This is how I connect to database on my local pc:
How do I connect it with RDP now? Do I need to make any changes to the database like whitelisting the IP and if so How do I do it?
Thanks
If the database is running on your local computer inside your firewall/router, then it cannot be reached from the Internet. If you control your router, you can try forwarding port 5432 on your public IP to port 5432 on your Windows computer. However, it might be better if you just moved the Postgres instance to your cloud instance.
I have a simple Python Flask web server, running in a docker container along with an Nginx reverse proxy, and a MySQL database.
When the docker compose is run in network_mode: 'host', everything (nginx-python-mysql) works fine.
But when it is switched to bridge networking, Nginx and the python endpoint app seem to work fine, but the python app is unable to connect to the MySQL instance.
I am exposing the MySQL port 3306. Everything is running on a CentOS-7 vm.
The Python Flask app is running on an gunicorn Python WSGI HTTP Server instance. The MySQL database is based on tutum/mysql.
I have tried both pymysql and SQLAlchemy clients on the python endpoint, and I can only get them to connect to the mysql server in host network_mode.
And as far as I can tell from the docker instance info, the MySQL container is fine, and on the same network as the python endpoint container.
Unfortunately, this is all running on an air gaped server, so its difficult to post the config files here, but the only difference between the host and bridge mode settings is that the nginx ssl config proxy pass has https://endpoint instead of https://localhost, and connecting via https to the python app works in both host and bridge modes. The python app connects to the mysql database on host 0.0.0.0
What could cause the python app to mysql database connection problem to only work in host mode?
I launched an AWS linux instance and installed and ran mongo as instructed here. The mongo service is running and accepting connections on 27017. However, when I go to the server publik dns with port 27017 the server does not respond and I don't see the default mongo message.
I am trying to run a Python(Flask) server on another instance and trying to connect to the mongo server using the private ip, but the connection does not happen. I get this error message on the terminal :
pymongo.errors.ServerSelectionTimeoutError: xxx.xx.xx.xx:27017: [Errno
111] Connection refused
Is this not the right way to use mongo db on aws ? If this approach is feasible, what is causing the connection to not happen ?
All inputs appreciated, much thanks!
It is possible that your mongodb is configured to only accept connection from local host. Edit /etc/mongod.conf file to comment out the line that bindIP like in the example below -
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
This question already has answers here:
Lost connection to MySQL server at 'reading initial communication packet', system error: 0
(40 answers)
Closed 9 years ago.
I want to establish a connection between my local machine and MySQL database server via Python.
Can someone tell me how to "bind-address with localhost"?
Can someone tell me how to "bind-address with localhost"?
This is a MySQL configuration directive.
Edit the global my.ini file, in the [mysqld] section:
[mysqld]
# -- various other settings
port = 3306
bind-address = 127.0.0.1
# -- other settings
Save this file, and then restart your server.
Edit
If you want to connect to your local Windows instance of MySQL, simply use 127.0.0.1 as the server's address.
If you want to connect to your remote server, the one running Linux then it is a bit complicated:
First, make sure MySQL is listening on the public IP of the Linux server. Change the line bind-address = and set it to the public IP of your server.
Make sure port 3306 isn't blocked by any firewall.
The user that you use to connect to the server needs to have rights to connect from a remote IP. By default, users are only given rights to connect from localhost - in other words they can only connect if the program is running on the same machine as the server itself.
To grant a user access from a remote IP, run this command from the mysql> shell when logged in with the MySQL root user:
GRANT ALL on somedb.* to someuser#8.8.8.8 identified by 'somepassword';
If you want to grant access to someuser from any remote IP:
GRANT ALL on somedb.* to someuser#% identified by 'somepassword';
After those steps, make sure to restart the MySQL server so it will read the changes in the configuration.