如何确定MySQL事务中是否有未提交的写操作? [英] How do I determine if I have uncommitted writes in a MySQL transaction?
问题描述
我正在使用一个非常复杂的代码库,希望对它与MySQL的工作方式进行一些自省. (请注意,我正在使用InnoDB).
I'm working with a very complex codebase and wish to do some introspection of how it works with MySQL. (Note that I'm using InnoDB).
特别是,在我正在编写的方法中,我希望确定其开放式db连接中是否有未完成的(未提交的)写入.
Specifically, in a method I'm writing, I wish to determine if there are any outstanding (non-committed) writes in its open db connection.
是否有任何MySQL命令(或其他方法)来检测是否存在未提交的写入? (或用另一种方式来说,确定COMMIT是否将不做任何修改.)
Is there any MySQL command - or other means - to detect if there are uncommitted writes? (or phrased another way, determine if COMMIT will make no modifications).
推荐答案
这是一个非常有趣的问题.我认为没有确定发送commit是否会在您正在运行的会话中产生作用的明确方法.
This is a pretty interesting question. I don't think there is a definite way to determine if issuing commit will or will not make a difference in the session you are running.
您可以使用show innodb status
或显示引擎innodb查看交易状态,但我认为您无法对这些交易进行提交.
You can see transactions with show innodb status
or show engine innodb status but I don't think you can issue commit on those transactions.
INNODB_TRX
table in information_schema will show currently executing transations: https://dev.mysql.com/doc/refman/5.5/en/innodb-trx-table.html and again there's not much you can do to force-commit them. You can roll them back by killing the associated process.
如果您正在使用开始交易存储过程中,您可以手动处理提交和回滚.您甚至可以设置自动提交为0控制何时回滚以及何时提交.
If you are running a transaction using START TRANSACTION in a stored procedure, you can handle commit and rollback manually. You can even set autocommit to 0 to control when to rollback and when to commit.
这篇关于如何确定MySQL事务中是否有未提交的写操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!