How to connect to my PostgreSQL database from RDP? - python

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.

Related

Postgresql cannot connect to server

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.

Can't connect to MariaDB server remotely using TCP

I know this kind of a question has been asked for a thousand times, but I still need to, because I assume that I'm doing everything right here and internet hasn't helped my out.
So I'm trying to remotely connect to my MySQL server (hosted by MariaDB 10.3.29 on Raspbian 10, Raspberry Pi 4). I've been trying to connect by using address 192.168.1.4 on my phone, another computer on another network, by using mysql server command line on a Windows PC and even on iOS using a QueryDB app.´
The exact error message I'm getting is:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.4:3306' (10060)
Config file:
/etc/mysql/mariadb.conf.d/50-server.cnf
has this to be able to connect from any IP:
bind-address = 0.0.0.0
as I think it should.
Also my ufw has mysql allowed, and port 3306 that I'm using, is allowed from anywhere.
I've done this:
GRANT ALL ON *.* TO 'user'#'%' IDENTIFIED BY 'my_pass';
FLUSH PRIVILEGES;
And to be sure I've checked that with
SELECT User, Host FROM mysql.user;
All seems to be OK. I still can't connect remotely. Of course I can connect from localhost, like another computer on my LAN.
I've also opened port 3306 on my ASUS router settings like this:
ASUS router port forwarding
Is that like it should be?
I really can't figure out anything causing this problem. According to information I've gathered, everything should be working. Thanks!
Ok, so after searching for three days I got this.
The problem wasn't with the MySQL but with the Apache. I needed to forward Apache's port 80 to connect to my Public IP address, not local of course.
So it works now!

How to connect oracle database that is accessible from remote desktop in local machine using python?

Detail about question:
I use following step to connect oracle from local machine.
connect to remote desktop by ip(xx.xx.xxx.xxx) and username-password
open sql developer and connect to database using hostname, port, SID/service name and username-password.
Can I do this task from local machine itself using python?
Note: I am able to connect to databases that are accessible from local machine using cx_oracle.
The firewall on the DB machine maybe set to allow Remote Desktop Protocol only. Please check the firewall setting on the DB machine.

How to access MySQL Database on a Bluehost server remotely through Python

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.

Configuring Remote MYSQL with a Dynamic IP

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

Categories