ylnor ylnor - 3 months ago 20
MySQL Question

Remotely connect to MySQL with Python mysql.connector

The following code (ran from a different machine than the mysql server, within the same LAN), to locally connect to MySQL database using Python3 and mysql.connector works:

import mysql.connector
cnx = mysql.connector.connect(host='', database='import_test',user='user_builder', password='password***', port=3309)

However, the following code, to remotely connect to the same database, does NOT work:

import mysql.connector
cnx = mysql.connector.connect(host='http://imaginarywebsite.ddns.net', database='import_test',user='user_builder', password='password***', port=3309)

Instead, I receive the following error:

File "C:\Users\****\AppData\Roaming\Python\Python34\site-packages\mysql\connector\network.py", line 464, in open_connection
errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'http://imaginarywebsite.ddns.net:3309' (11004 getaddrinfo failed)

Here is an extract of my my.cnf file:

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/


port = 3309
bind-address =

So, here is what currently works:

  • Connect locally to the databse using address, so I am sure the problem does not come from 'privileges granting' or any login/password/port error.

  • Connect remotely via phpmyadmin using http://imaginarywebsite.ddns.net/phpmyadmin, so I am sure the problem does not come from my DNS server.

And here are my 3 questions :

  1. Any Idea where the problem can come from?

  2. Should using SSH connection be a solution to my problem?

  3. If SSH is the solution, is it possible to use SSH parameters through mysql.connector since it does not seem to be presented in the official documentation?



Actually the answer was to use the global IP address of my server instead of the domain name, probably an issue of name management.

Replacing host='http://imaginarywebsite.ddns.net' by 'host=85.23.56.****" made it work.