Home > Database > Mysql Tutorial > Introduction to Mysql transaction isolation level content (read commit)

Introduction to Mysql transaction isolation level content (read commit)

不言
Release: 2019-01-09 10:55:05
forward
3819 people have browsed it

The content of this article is an introduction to the content of Mysql transaction isolation level (read commit). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Mysql transaction isolation level read commit

View mysql transaction isolation level
mysql> show variables like '%isolation%';
+---------------+----------------+
| Variable_name | Value          |
+---------------+----------------+
| tx_isolation  | READ-COMMITTED |
+---------------+----------------+
1 row in set (0.00 sec)
Copy after login

You can see that the current transaction isolation level is READ-COMMITTED read commit

Let’s look at the transaction isolation details under the current isolation level and open two query terminals A and B.

There is a order table below, the initial data is as follows

mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      1 |
+----+--------+
1 row in set (0.00 sec)
Copy after login
Copy after login
The first step is to open the transaction in both A and B
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
Copy after login
The second step Query the number value in both terminals
  • A

 mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      1 |
+----+--------+
1 row in set (0.00 sec)
Copy after login
Copy after login
  • B

 mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      1 |
+----+--------+
1 row in set (0.00 sec)
Copy after login
Copy after login
The third step changes the number in B to 2, but does not commit the transaction
mysql> update `order` set number=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Copy after login
The fourth step queries the value in A
mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      1 |
+----+--------+
1 row in set (0.00 sec)
Copy after login
Copy after login
It is found that the value in A has not been modified.
The fifth step is to submit transaction B and query the value in A again
  • B

mysql> commit;
Query OK, 0 rows affected (0.01 sec)
Copy after login
  • A

mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      2 |
+----+--------+
1 row in set (0.00 sec)
Copy after login
Copy after login
It is found that the value in A has changed
The sixth step is to submit the transaction in A and query the values ​​of A and B again.
  • A

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      2 |
+----+--------+
1 row in set (0.00 sec)
Copy after login
  • B

mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      2 |
+----+--------+
1 row in set (0.00 sec)
Copy after login
Copy after login
Found A and B The values ​​have been changed to 2.

The following is a simple diagram

Introduction to Mysql transaction isolation level content (read commit)

We can see that the transaction isolation level is Read Committed In the case of B, after the transaction in B is submitted, the result of B transaction submission can be read even if A has not submitted. This solves the problem of dirty reading.

The above is the detailed content of Introduction to Mysql transaction isolation level content (read commit). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
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