michltm michltm - 1 year ago 66
MySQL Question

Python MySQLdb connection to online database

While I have no problems to connect to my localhost database that way:

import MySQLdb

localdb = MySQLdb.connect( host="",

I couldent connect to my online database.

Usually I access manually to this database with phpmyadmin and the adress is something like

So I tried something like

onlinedb = MySQLdb.connect( host="" ...


onlinedb = MySQLdb.connect( host="" ...

But I get an error such as:

OperationalError: (2003, "Can't connect to MySQL server on '' (10061)")

Answer Source

It sounds like is the URL of PHPMyAdmin (the thing you open in the browser). If so, the database may not be hosted on the machine with IP You should check how PHPMyAdmin connects to the database. If PHPMyAdmin connects to, that probably means the database doesn't listen on the external IP address, and can't be reached over the network.

If you have ssh access to you can check that with the netstat command:

$ netstat -pant | grep LISTEN | grep 3306
tcp    0    0*    LISTEN      -

The above indicates that MySQL is listening on all IPs, and barring any firewalls, you should be able to connect to the database.

Otherwise, if it says, the database can only be accessed from the machine itself and not over the network. In that case you can use an SSH tunnel.