Analysis of Mysql Repeatable-read isolation level _mysql

Source: Internet
Author: User

Repeatable-read can be read repeatedly, and the contents of the Select table in set autocommit= 0 or start transaction state will not change. This isolation level may result in something that has been read that has been modified.

Like what:

Read a field in one row a=1

In reply two, this field modifies the a=0 and submits

And then update this field a=0, you will find that the number of affected rows is 0, so you can determine whether the change was successful based on the number of rows affected by 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 affected rows here is 0, and we can determine whether the update was successful based on this value, which is useful when you need to change the status of some rows!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.