Home > Database > Mysql Tutorial > body text

浅析MYSQL REPEATABLE-READ隔离级别_MySQL

WBOY
Release: 2016-06-01 13:05:24
Original
1192 people have browsed it

REPEATABLE-READ 即可重复读,set autocommit= 0或者START TRANSACTION状态下select表的内容不会改变。这种隔离级别可能导致读到的东西是已经修改过的。

比如:

回话一中读取一个字段一行a=1

在回话二里这个字段该行修改a=0,并且提交

回话一中再update这个字段a=0,会发现受影响行数是0,这样就可以根据受影响行数是0还是1判断此次修改是否成功!

这在某些程序里会很有用!

会话1:

mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from test.dd where id=1;
+----+------+
| id | aa |
+----+------+
| 1 | 2 |
+----+------+
1 row in set (0.00 sec)

会话2:

mysql> update test.dd set aa=1 where id=1;
Query OK, 1 row affected (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 0

会话3:

mysql> select * from test.dd where id=1;
+----+------+
| id | aa |
+----+------+
| 1 | 2 |
+----+------+
1 row in set (0.00 sec)

mysql> update test.dd set aa=1 where id=1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

此处的受影响行数为0,我们可以根据这个值判断这次update是否成功,这在需要更改某些行的状态位的时候是比较有用的!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!