例示Innodb中的read commited和repeatable read

本文读者须已经了解mysql的mvcc机制。

假定某行某字段值为100; 以下所有的查询和修改都针对这个字段。

事务甲                                                                   事务乙

——————————————————————————-

set commit = 0                                                  set commit = 0

select …

(值为100)

update … = 200;

selet …

(值为200, 自已事务下的修改是立即可见的)

                                                                          update … = 300;

select …

(仍为200, 右边事务未提交,不关我的事)

                            

                                                                          commit;

select …

(

如果level=read commited, 值为300, 可以读到其它事务的已提交修改

如果level=read repeatable, 值仍为200, 其他事务即使提交了也不关我的事

)

commit;

—-

select …

(值为300,这个不用解释)

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.