Python MySQLdb connection to online database
<p>While I have no problems to connect to my localhost database that way:</p>

<pre><code>import MySQLdb

localdb = MySQLdb.connect( host="127.0.0.1",    
                           user="root",         
                           passwd="password",           
                           db="events")
</code></pre>

<p>I couldent connect to my online database.</p>

<p>Usually I access manually to this database with <em>phpmyadmin</em> and the adress is something like <strong>212.227.000.000/phpmyadmin</strong></p>

<p>So I tried something like </p>

<pre><code>onlinedb = MySQLdb.connect( host="212.227.000.000" ...
</code></pre>

<p>or</p>

<pre><code>onlinedb = MySQLdb.connect( host="212.227.000.000/phpmyadmin" ...
</code></pre>

<p>But I get an error such as:</p>

<pre><code>OperationalError: (2003, "Can't connect to MySQL server on '212.227.000.000' (10061)")
</code></pre>

<p>It sounds like <code>212.227.000.000/phpmyadmin</code> 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 212.227.000.000. You should check how PHPMyAdmin connects to the database. If PHPMyAdmin connects to 127.0.0.1, that probably means the database doesn't listen on the external IP address, and can't be reached over the network.</p>

<p>If you have ssh access to 212.227.000.000 you can check that with the <code>netstat</code> command:</p>

<pre><code>$ netstat -pant | grep LISTEN | grep 3306
tcp    0    0 0.0.0.0:3306        0.0.0.0:*    LISTEN      -
</code></pre>

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

<p>Otherwise, if it says <code>127.0.0.1:3306</code>, the database can only be accessed from the machine itself and not over the network. In that case you can use an SSH tunnel.</p>

python mysql