我如何发现是否有事务在MySQL中打开? [英] How can i found out if there is transaction open in MySQL?

查看:242
本文介绍了我如何发现是否有事务在MySQL中打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道是否有事务在mySQL中打开?我需要启动新的一个,如果没有事务打开,但我不想开始新的一个,如果有一个正在运行,因为这将提交运行事务。

How can i find out if there is transaction open in mySQL? I need to start new one if there is no transaction open, but i don't want to start new one if there is one running, because that would commit that running transaction.

UPDATE:

我需要在我的应用程序的一个方法中查询数据库,作为更大的交易的一部分,或者就像它应该是一个自己的交易。更改应用程序以跟踪是否已打开事务将更加困难,因为它可以从许多代码段开始。虽然这是可能的,我在寻找的解决方案,将更快的实现。

i need to query database in one method of my application, but that query could be called as part of bigger transaction, or just as it should be a transaction on its own. Changing application to track if it has open a transaction would be more difficult, as it could started from many pieces of code. Although it would be possible, i'm looking for solution that would be faster to implement. Simple if statement in sql would be effortless.

谢谢

推荐答案

我假设你这样做是一次性的,而不是试图建立一些可以编程的东西。您可以使用以下命令获取当前活动进程的列表:SHOW PROCESSLIST

I am assuming you are doing this as a one-off and not trying to establish something that can be done programatically. You can get the list of currently active processes using: SHOW PROCESSLIST

http://dev.mysql.com/doc/refman/5.1/en/show-processlist.html

如果你想要一些程序性的东西,那么我建议在你的事务开始时对表进行显式锁定,并在结束时释放它。

If you want something programatic, then I would suggest an explicit lock on a table, at the beginning of your transaction and release it at the end.

这篇关于我如何发现是否有事务在MySQL中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆