skip to Main Content

I have a mysql Database which is hosting on a windows server under the domain: https://<some-domain>.net/phpmyadmin/index.php and I’m trying to connect to this database in my flask app from outside the server but it cannot connect to server.

my python code:

conn = mysql.connector.connect(host='https://<some-domain>.net/phpmyadmin/index.php',
                               user='user',
                               password='password',
                               database='db',
                               port='3306')

I also tried with the IP-Address of the domain and it did not worked.
locally on Windows-Server it works without any problem, but when I try to reach the database from outside the Windows-Server, it would not connect.

With Domain as host I get an:

mysql.connector.errors.InterfaceError: 2003: Can’t connect to MySQL server on ‘%-.100s:%u’ (%s) (Warning: %u format: a real number is required, not str)

With IP-Address as host I get an:

mysql.connector.errors.InterfaceError: 2003: Can’t connect to MySQL server on ‘217.237.79.165:3306’ (10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)

Does anyone have a solution how to connect to the database from outside the windows Server?

2

Answers


  1. Most likely you’re running into a firewall issue on your windows host or the network the windows host is on.

    "With IP-Address as host I get
    an:mysql.connector.errors.InterfaceError: 2003: Can’t connect to MySQL
    server on ‘217.237.79.165:3306’ (10060 A connection attempt failed
    because the connected party did not properly respond after a period of
    time, or established connection failed because connected host has
    failed to respond)"

    this tells me that the box that your flask app is sitting on can’t even communicate with the IP of your windows host. You will want to troubleshoot that.

    run a traceroute 217.237.79.165 or tracert 217.237.793.165 to see where the connection is dying.

    If your flask app is sitting on another windows box, you can use the powershell command:

    Test-NetConnection -computer 217.237.79.165 -port 3306
    

    to get an idea if you’re having issues at the port level as well.

    good luck

    Login or Signup to reply.
    • hostname: this should be IP address of your Window server, the value that you filled in is URL of phpmyadmin, which is a management tool of MySQL (that you installed along side with your MySQL server)
    • port: this should be an integer, in this case port=3306 (default port of MySQL)
    • you need to update FW on Window server to make it accept connection from client to port 3306

    arguments of Python connector

    For mysql.connector.connect method on Python:
    https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search