SQLalchemy 不会执行大型数据库查询
尝试使用以下代码从 mariaDB 查询大约 200k 行。
with engine.connect() as connection:
print("test1")
result = connection.execute(sqlalchemy.text(query))
dates = [print("test2") for row in result]
print(len(dates))
engine.dispose()
它第一次奏效。然后第二次打印后冻结。然后在用 ctrl + c 中断它后,可以再次运行它。等等test1
可能的原因是什么,是否处理了错误的连接?有没有可能的解决方法?
数据库与其他系统配合良好。对于较小的 query,则不会发生这种情况。
在 syslog 上发现以下错误: (在 <> 中隐藏了一些细节)
Jul 5 16:52:46 <machine_name> mysqld[1571843]: 2024-07-05 16:52:46 3094934790 [Warning] Aborted connection 3094934790 to db: '<db_name>' user: '<db_user>' host: '<db_host>' (Got an error reading communication packets)