I currently have a Python connector script that I run on my Bluehost server locally. In the past, I've tried to run this script remotely, i.e. login remotely with the Python script on my own local machine, but I ended up just running it on the server. In my current situation, I need to run a script every 10 minutes on the server, but I don't have root access, so I can't create a cron job. I can, however, set up a Windows task to run my script every 10 minutes remotely, but when I try, I'm unable to connect to my domain's database. Is there any documentation or work around for this?
Here's my code for connecting to the database remotely:
cnx = mysql.connector.connect(user='database_user',
password='database_password',
host='www.example.com',
database='database_name')
When I try to use this script remotely, I get the following error message:
InterfaceError: 2003: Can't connect to the MySQL server on 'example.com:3306'
(10061 No connection could be made because the target machine actively refused it)
You have to enable access for the IP address of the computer you are trying to access the server from. By default the database server doesn't allow outside connections. You'll do this by logging into your host (Bluehost)
Log into cPanel and click the Remote MySQL icon, under Databases.
Type in the connecting IP address, and click the Add Host button.
Click Add, and you should now be able to connect remotely to your
database.
Log in your bluehost account
Click on Advanced
Click the Remote MySQL icon, under MySQL® Databases category DATABASES.
Type in the connecting IP address the IP that you want be enabled to access bluehost mysql database (eg. your public IP - https://whatismyipaddress.com/), and click the Add Host button
You should now be able to connect remotely to your database
Remember that you have to create user with the permission for the database.
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 created a connection to a remote, tunneled MySQL server over the PyCharm GUI in the "Database" menu.
I'm trying to use this connection in the code itself, without connecting manually again to the SQL server and tunelling over SSH in the code.
Is this possible? I couldn't find anything relevant on the internet yet.
Thanks!
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 question how can I connect to VPS server and interact with MySQL database using python on my local machine.
I would like to make program using PyQT that connect to my server and update, take sth from db.
I know that there is MySQLdb module but from what I know i cannot connect to VPS server, because in connect method it doesn't take server password argument.
I am connecting my python software to a remote msql server.
i have had to add an access host on cPanel just for my computer but the problem is the access host, which is my IP, is dynamic.
How can i connect to the remote server without having to change the access host everytime?
thanks guys, networking is my weakness.
Your best option is probably to find a [dynamic DNS] provider. The idea is to have a client running on your machine which updates a DNS entry on a remote server. Then you can use the hostname provided instead of your IP address in cPanel.
There is a bash script for linux which can be run to check continuously whether the IP has changed and update the providers record if necessary. It is for cPanel and requires editing the code to insert the credentials, which is trivial.
Download from github