您的位置:首页 > 数据库 > MySQL

mysql嵌套事务的问题

2016-01-21 13:45 585 查看
今天跟同事在讨论一段代码,我建议使用嵌套事务解决。当场用mysql示范,结果发现了以下问题

</pre><p><pre name="code" class="html">insert into table1 values('abc',0);
set autocommit=0;
start transaction;
update table1 set value=1;
start transaction;


这时候另一个链接中会看到value=1.

查了资料:

在官方文档的隐式提交这一节https://dev.mysql.com/doc/refman/5.6/en/implicit-commit.html

Transactions cannot be nested. This is a consequence of the implicit commit performed
for any current transaction when you issue a START TRANSACTION statement or one of its synonyms.

大意是:事务不能嵌套。当你发起start transaction或者类似的操作时,任何当前事务都会被隐式的提交。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql 事务 transactions