python - Python MySQL 连接器超时
问题描述
使用 Python MySQL 连接器将记录插入 MySQL 数据库。流程在大约 98% 的时间里有效。我从服务器收到间歇性超时响应。其他时候脚本只是挂起,什么也没有发生,这是最糟糕的情况。
我可以使用线程超时/终止进程吗?
我可以在执行或提交语句上设置超时吗?
import mysql.connector
try:
mydb = mysql.connector.connect(host="...", user="...", password="...", database="...")
mycursor = mydb.cursor()
except Exception as e:
print(e)
#Seems to always work up to this point
sql = "INSERT INTO test (name,tagline,location,experience) VALUES (%s, %s, %s, %s)"
val = ('test', 'test', 'test', 'test')
try:
mycursor.execute(sql, val)
mydb.commit()
except Exception as e:
print(e)
mycursor.close()
mydb.close()
解决方案
推荐阅读
- r - 使用所有递归索引作为列名将嵌套列表转换为 data.frame 并用 NA 填充缺失的列
- python - 替换 Python Pandas 数据框中的相应列值
- python - 在 pandas 中用反引号解码对象
- reactjs - React - 错误:渲染的钩子比上一次渲染时更多
- python - 集成 pyenv virtualenv conda 和 ASE 的最佳实践
- discord.py - Discord.py 垃圾邮件
- r - 使用 fwrite 导出 csv 后将分类字段转换为连续字段
- mongodb - 在 MongoDb 上使用地理空间索引的汉明距离?
- java - 过程 myProcedure (text, text) 不存在 提示:没有过程与给定名称和参数类型匹配
- php - wordpress 404.php 页面未加载排队脚本