我如何发现是否有事务在MySQL中打开?

编程入门 行业动态 更新时间:2024-10-27 20:26:23
本文介绍了我如何发现是否有事务在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

dev.mysql/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中打开?

本文发布于:2023-10-24 09:56:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事务   发现   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!