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

时间:2016-06-14 10:15:07

标签: python mysql

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

_db_config = { 'user': 'root', 'password': '1111111', 'host': '10.20.30.40', 'database': 'ddb' }

  • _connection = mysql.connector.connect(**_db_config) # connect to a remote server
  • _cursor = _connection.cursor(buffered=True)
  • _cursor.execute("""SELECT * FROM database LIMIT 1;""")

在某些情况下,对_cursor.execute()的调用会挂起,没有异常

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

2 个答案:

答案 0 :(得分:0)

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

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

这是一个与" pymysql"一起工作的帖子。 Gives small idea to with with mysql and python3

答案 1 :(得分:-1)

转移到MySQLdb(而不是mysql.connector)解决了所有问题: - )