[英]Python MySQL Performance: Runs fast in mysql command line, but slow with cursor.execute
I'm writing a script for exporting some data. 我正在编写用于导出一些数据的脚本。
Some details about the environment: 有关环境的一些细节:
Details about the SQL: 有关SQL的详细信息:
When I run the SQL statement in the mysql command line, it takes 3-4 seconds 当我在mysql命令行中运行SQL语句时,它需要3-4秒
When I run the SQL in my python script the line cursor.execute(sql, [id]) takes over 60 seconds. 当我在python脚本中运行SQL时,cursor.execute(sql,[id])行需要60秒钟以上。
Any ideas on what might be causing this? 关于什么可能导致此的任何想法?
Two ideas: 两个想法:
MySQL may have query caching enabled, which makes it difficult to get accurate timing when you run the same query repeatedly. MySQL可能启用了查询缓存,这使得在重复运行相同查询时很难获得准确的时间。 Try changing the ID in your query to make sure that it really does run in 3-4 seconds consistently. 尝试更改查询中的ID,以确保它确实能够在3-4秒内持续运行。
Try using strace on the python process to see what it is doing during this time. 尝试在python进程上使用strace以查看其在这段时间内的运行情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.