python - Python MySQL-Connector 无法在 Windows VPS 上间歇性连接
问题描述
我正在使用 Windows VPS 抓取数据。我正在使用 Python MySQL-Connector 将这些抓取的数据上传到 Linux 专用服务器。
import mysql.connector
mydb = mysql.connector.connect(
host="...",
user="...",
password="...",
database="...",
connection_timeout=60
)
mycursor = mydb.cursor()
大约 25% 的时间会失败,或者需要 20 多秒。当它失败时,我得到一个 10060 错误。问题更可能出在我的 Linux 服务器上,还是更可能出在我的 Windows VPS 上?帮助由衷感谢。这是错误消息:
2055: Lost connection to MySQL server at '[IP]:3306', system error: 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.
解决方案
查看错误消息,我怀疑这是由端口被阻塞引起的(MySQL 服务器的默认 TCP/IP 端口是 3306)。
检查 3306 端口是否忙:
netstat -tulpn | grep 3306
然后在再次运行您的应用程序之前尝试释放该端口。
推荐阅读
- java - Quarkus 应用程序与多个实例的协调
- git - 无法 git push 但 git clone 工作
- python - 如何从数据框中选择多个列,并在其中我需要在同一代码中使用现有列创建两个新列?
- javascript - 递归函数总是返回未定义的 JS
- aframe - 我对框架模型视图、立方体而不是我的模型有问题
- php - php在对象详细信息中解析数组
- flutter - 如何在不同路由之间传递变量引用?
- angular - 有没有办法以角度反应形式搜索(过滤)FormArray?
- c# - 为什么VS2017调试不会停在dllmain断点?
- python-3.x - 如何从棒球运动员的统计数据中获取百分比