Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用MySQL cursor.execute()(Python驱动程序)挂起_Python_Mysql - Fatal编程技术网

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

调用MySQL cursor.execute()(Python驱动程序)挂起,python,mysql,Python,Mysql,我正在使用python驱动程序mysql.connector并执行以下操作: _数据库配置={ '用户':'根', “密码”:“1111111”, ‘主持人’:‘10.20.30.40’, “数据库”:“ddb” } _connection=mysql.connector.connect**\u db\u config连接到远程服务器 _cursor=\u连接。cursorbuffered=True _cursor.executeSELECT*来自数据库限制1; 在某些情况下,对_cursor.

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

_数据库配置={ '用户':'根', “密码”:“1111111”, ‘主持人’:‘10.20.30.40’, “数据库”:“ddb” }

_connection=mysql.connector.connect**\u db\u config连接到远程服务器 _cursor=\u连接。cursorbuffered=True _cursor.executeSELECT*来自数据库限制1; 在某些情况下,对_cursor.execute的调用会毫无例外地挂起


顺便说一句,当连接到本地MySQL服务器时,似乎还可以

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

优化您的查询 使用更好的连接器驱动程序 我通常使用python3.x,为此我使用pymysql或pyodbc 哪些是新的和优化的驱动程序
下面是一篇关于使用pymysql而不是mysql的帖子。connector解决了所有问题:-

删除;从第三line@BillalBEGUERADJ起初我以为它能解决我的问题,但不幸的是,它不能。我仍然会遇到这些挂起,超时也不能解决它:-SQL查询本身并不是消耗时间的东西。。。当您直接从命令行运行查询时,您是否观察到了同样的情况?如果从IPython或Jupyter运行查询,我会遇到这些问题。以python文件passok的形式运行它。另一件事是,使用本地服务器通常我连接到远程服务器也可以正常工作,所以问题一定是远程连接,因为数据库中缺少case表。cursor没有给出任何错误消息。我怀疑查询太大,因为OP正在使用限制1,并且正在请求通配符。那不应该太多,对吗?