我正在使用 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/