A brief analysis of MYSQL ES1en ES2en isolation level

  • 2020-06-23 02:06:14
  • OfStack

REPEATABLE-READ can be read repeatedly, set autocommit= 0 or START TRANSACTION the contents of the select table do not change. This isolation level may cause the reading to be modified.

Such as:

Answer 1 reads 1 field 1 line a=1

In Reply 2, this field changes a=0 and commits

In reply 1, add update to the field a=0, and you will find that the number of affected rows is 0. In this way, you can judge whether the modification is successful according to whether the number of affected rows is 0 or 1!

This can be useful in some programs!

Session 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)

Session 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

Session 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

The number of rows affected here is 0, and we can use this value to determine if update succeeded this time, which is useful when we need to change the state bit of some rows!


Related articles: