Python MySQLdb 在连接尝试时冻结
我正在尝试在 Python 中使用 MySQLdb 连接到我在 Pagoda Box 应用程序上建立的数据库。首先,我使用以下命令打开到数据库的 Pagoda 隧道:
$ pagoda tunnel -a <app-name>
它返回隧道已成功打开,连接在 127.0.0.1:3307 上可用。我在 Python IDLE 中运行以下命令:
import MySQLdb
conn = MySQLdb.connect(host = '127.0.0.1', port=3307,user='user',passwd='pass')
之后 IDLE 屏幕冻结(即它卡在无限循环中的当前命令上)。似乎挂在connections.py中的Connect()方法上。我不确定这是为什么或者如何解决它。非常感谢您的任何指导
===========================================更新============================================
我让脚本运行更长时间,并且我还尝试使用 phpmyadmin 以及本地计算机上的简单 mysqli_connect() 脚本进行连接。他们都返回:
MySQL错误:2013,“在‘读取初始通信数据包’时失去与MySQL服务器的连接,系统错误:0”
这似乎是问题的根源。我可以修复我的电脑上的某些配置来消除该问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为一般规则,每当您试图找出程序停止的位置时,您可以使用 strace (strace myprog.py) 启动它,也可以在 pid 上运行 strace (strace -p pidnum)
例如,我的 ipython 有pid 为 12608,所以我运行
然后运行
,我看到 strace 产生了成功的连接,
我不确定这如何与 Pagoda Box 一起使用,但在正常的终端会话中,这就是我开始的地方
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
then I run
and I see the strace produce successful connections
I am not sure how this works with Pagoda Box, but in a normal terminal session this is where I would start