python - 调用 MySQL cursor.execute()(Python 驱动程序)挂起

标签 python mysql

我正在使用 python 驱动程序 (mysql.connector) 并执行以下操作:

_db_config = { '用户':'根', '密码':'1111111', '主机':'10.20.30.40', '数据库':'ddb' }

  • _connection = mysql.connector.connect(**_db_config) # 连接到远程服务器
  • _cursor = _connection.cursor(buffered=True)
  • _cursor.execute("""SELECT * FROM database LIMIT 1;""")

在某些情况下,对 _cursor.execute() 的调用挂起,无一异常(exception)

顺便说一句,当连接到本地 MySQL 服务器时,它似乎没问题

最佳答案

结果可能由于大型数据库或未优化的查询而挂起。 你可以尝试以下事情

  • 优化您的查询
  • 使用更好的连接器驱动程序 我通常使用 python3.x,为此我使用“pymysql”或“pypyodbc” 这是新的和优化的驱动程序

这里是一个使用“pymysql”的帖子 Gives small idea to with with mysql and python3

关于python - 调用 MySQL cursor.execute()(Python 驱动程序)挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37809163/

相关文章:

PHP- 提供 ID 时自动填充数据

php - MySQL:无法在 MySQL View 中插入

mysql 选择每个项目的最大日期

python - 即使使用 --insecure 后 Django 图像也不会加载

python - 在 Pandas 中将 "year"和 "week of year"列转换为 "date"

mysql - 如何在 MySQL 中按年和月分组

MySQL 更新一条记录的第一个实例

python - 在 Flask 中 unpickling 对象时出现属性错误

python - 如何从字符串生成带有 selenium/phantomjs 的 png 文件?

python - 在 C 中使用 Python