Unable to connect remotely to mysql database hosted online - python

I am trying to remotely connect to a mysql database from my company network, using the mysql.connector module in python. The db is hosted online (siteground.com).
Error: Error while connecting to MYSQL 2003: Can't connect to MySQL server on.... (10061 no connection could be made because the target machine actively refused it)*
I have the correct hostname, username, password etc.., and have added my company's public IP address as an allowed remote access host.
I have been able to successfully connect using the exact same procedure from a python notebook hosted on google colaboratory (in google drive).
Any ideas on what the issue might be?
Thank you

Related

Migrating from Azure Sql to Azure Synapse, can't connect to Synapse in Airflow

So we are in the process of migrating from Azure SQL DB to Azure Synapse SQL Pools. I figured setting Airflow up to use the new database would be as simple as changing the server address and credentials, but when we try to connect to the database via Airflow it throws this error:
40532, b'Cannot open server "1433" requested by the login. The login failed.
We use the generic mssqloperator and mssqlhook. I have verified the login info, pulled the server address directly from Synapse, and the synapse connection string shows port 1433 is correct, so I am at a loss for what could be causing the issue. Any help would be appreciated.
Edit: The Airflow Connection schema we use is the Microsoft Sql Server Connection, with host being {workspace}.sql.azuresynapse.net, login being the admin login, password being the admin password, and port being 1433
The error is due to the port which was not enabled.
Make sure that port 1433 is open for outbound connections on all firewalls between the client and the internet.

cloud Sql connect from Local Python IDE

How to connect Google Cloud Sql from Local Python code?I am using Pycharm IDE.So I need the detail process to establish connection with google cloud mysql
You can find the detailed process here :
Connecting to Cloud SQL - MySQL
1.If you haven't already, set up a Python Development Environment by following the python setup guide and create a project.
2.Create a 2nd Gen Cloud SQL Instance by following these instructions. Note the connection string, database user, and database password that
you create.
3.Create a database for your application by following these instructions. Note the database name.
4.Create a service account with the 'Cloud SQL Client' permissions by following these instructions. Download a JSON key to use to
authenticate your connection.
5.Running locally : Launch proxy with TCP or Launch proxy with Unix Domain Socket

Connecting to Redshift via psycopg2 fails

I have whitelisted ec2 IP address but without 0.0.0.0/0 configuration, I can't connect to the Redshift database from psycopg2. What can be done about this situation where we want to request from a particular IP address.
Is this is the bug that exists when you try to connect it programmatically
Edit:
I tried to whitelist my local IP address and ran my program on the local server and it got connected. But I am not able to connect via my application hosted on EC2 instance.

Connecting through Python to a MySQL database hosted on a remote server with no direct access

I wish to connect to a database server through my local machine at work, but I do not have direct access to the database server (due to security reasons). The database server is accessible through another intermediary server which I can connect to.
I understand I can connect to the database if I run my script on the intermediary server, but is there any way through which I can connect to the database server directly through my local machine?
I am trying to do this in a Python script as I wish to read the data into a pandas dataframe (I can do this part once I can set up the connection).
If you have SSH access to that intermediary server you can connect via an SSH tunnel. This post describes how to do that: Enable Python to Connect to MySQL via SSH Tunnelling

Can MySQLdb on client machine connect to a database on a server machine?

I am not a network/web/internet programmer so please excuse my noobness in this area. I have gotten a website using a free hosting service. They include one MySQL database. Here are the details for the database:
port = 3306
host = "fdb4.biz.nf"
database = "1284899_6067"
user = "1284899_6067"
password = "somepass9351"
I am using MySQLdb module (installed on my CLIENT machine - not server) to connect to this database:
db = MySQLdb.connect(host=host, user=user, passwd=password, db=database,port=port)
But I get the following error:
OperationalError: (2003, "Can't connect to MySQL server on 'fdb4.biz.nf' (10060)
What I have already tried
tried two different databases from different hosts
tried changing the port
tried searching SO for similar answers but all others connect to 'local host'
What I think:
could this be caused by my firewall? I am using my school's internet. I don't think this could be it because I am on CLIENT so if anything it is the SERVER'S firewall.
Two questions
Can MySQLdb be used to connect to a db on a SERVER when it is imported on a CLIENT?
If yes, what am I doing wrong?
Thank you so much for any help, its greatly appreciated! Been stuck the whole day on this.
For security reasons, mysql only listens for connections from localhost. Error code 10060 is basically that: you are not allowed to connect remotely.
Solution: find a my.ini (or my.cnf in linux) and try to find a line:
bind-address = 127.0.0.1
this line says: allow only local connections. So, you should comment-out this line, or set your IP address.
Yes, MySQLdb can connect to remote hosts.
And your usage of the connect method is correct.
You should first check if you can connect to the remote mysql server from your mysql client.
In terminal you can type mysql -h hostname -u username -p databasename
This should prompt you for the password. Enter the password. Can you connect?
If you can't connect, then you have an access problem, and its not a python - mysqldb problem
Either the server is not reachable because it is behind a firewall, in that case your client machine's ip needs to be whitelisted. Check your firewall settings
Or, the mysql server running on the remote machine is configured to accept only local connections. I think this is the default, but I'm not sure. You should ssh into the server remote host where the database server is running, locate the my.cnf file on the server and check the settings. Depending on your mysql version, the configuration would look slightly different.
Or, the user that you're trying to connect as is not associated with the ip that you're trying to connect from. Mysql users have two parts, like this: 'username'#'host'. To enable a user to connect from all ips the user needs to look like this 'user'#'%'.
I hope I've given you enough to try to debug this issue.

Categories

Resources