Python MySQLdb freeze on connect attempt
I'm trying to use MySQLdb in Python to connect to the database I have established on a Pagoda Box application. First, I open the Pagoda tunnel to the database with:
$ pagoda tunnel -a <app-name>
and it returns that the tunnel has been successfully opened, with the connection available on 127.0.0.1:3307. I run the following commands in Python IDLE:
import MySQLdb
conn = MySQLdb.connect(host = '127.0.0.1', port=3307,user='user',passwd=开发者_开发知识库'pass')
after which the IDLE screen freezes (i.e. it is stuck on the current command on an infinite loop). It seems to be hung up on the Connect() method in connections.py. I'm not sure why this is or how to fix it. Any guidance you may have is greatly appreciated
=========================================UPDATE==========================================
I let the script run longer, and I additionally tried to connect using phpmyadmin, as well as a simple mysqli_connect() script on my local computer. All of them returned:
MySQL error: 2013, “Lost connection to MySQL server at 'reading initial communication packet', system error: 0”
This seems to be the root of the problem. Is there some configuration I can fix on my PC to eliminate the issue?
As a general rule whenever you are trying to figure out where a program is stalled you can either launch it with strace (strace myprog.py) or you can run an strace on the pid (strace -p pidnum)
for example, my ipython has a pid of 12608 so I run
strace -po 12608
then I run
con = MySQLdb.connect('xxx.xxx.xxx.xxx', 'user', '', 'database');
and I see the strace produce successful connections
setsockopt(4, SOL_SOCKET, SO_RCVTIMEO, "\2003\341\1\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0
setsockopt(4, SOL_SOCKET, SO_SNDTIMEO, "\2003\341\1\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0
setsockopt(4, SOL_IP, IP_TOS, [8], 4) = 0
setsockopt(4, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(4, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
I am not sure how this works with Pagoda Box, but in a normal terminal session this is where I would start
精彩评论