Print the actual query MySQLdb runs?(打印 MySQLdb 运行的实际查询?)
问题描述
我正在寻找一种在执行查询时调试查询的方法,我想知道是否有办法让 MySQLdb 在完成插入参数和所有这些之后打印出它运行的实际查询?从文档来看,似乎应该有一个 Cursor.info() 调用来提供有关上次查询运行的信息,但这在我的版本 (1.2.2) 上不存在.
I'm looking for a way to debug queries as they are executed and I was wondering if there is a way to have MySQLdb print out the actual query that it runs, after it has finished inserting the parameters and all that? From the documentation, it seems as if there is supposed to be a Cursor.info() call that will give information about the last query run, but this does not exist on my version (1.2.2).
这似乎是一个显而易见的问题,但经过我的所有搜索,我一直无法找到答案.提前致谢.
This seems like an obvious question, but for all my searching I haven't been able to find the answer. Thanks in advance.
推荐答案
我们在游标对象上发现了一个名为 cursor._last_executed 的属性,即使发生异常,它也会保存要运行的最后一个查询字符串.这对我们在生产中的生产来说比一直使用分析或 MySQL 查询日志更容易、更好,因为这两者都会影响性能并且涉及更多代码或更多相关的单独日志文件等.
We found an attribute on the cursor object called cursor._last_executed that holds the last query string to run even when an exception occurs. This was easier and better for us in production than using profiling all the time or MySQL query logging as both of those have a performance impact and involve more code or more correlating separate log files, etc.
不想回答我自己的问题,但这对我们来说效果更好.
Hate to answer my own question but this is working better for us.
这篇关于打印 MySQLdb 运行的实际查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:打印 MySQLdb 运行的实际查询?
基础教程推荐
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在多列上分布任意行 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
