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

Introduction to Mysql transaction isolation level content (read commit)

不言
不言forward
2019-01-09 10:55:053760browse

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)

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)
The first step is to open the transaction in both A and B
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
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)
  • B

 mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      1 |
+----+--------+
1 row in set (0.00 sec)
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
The fourth step queries the value in A
mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      1 |
+----+--------+
1 row in set (0.00 sec)
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)
  • A

mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      2 |
+----+--------+
1 row in set (0.00 sec)
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)
  • B

mysql> select * from `order`;
+----+--------+
| id | number |
+----+--------+
| 13 |      2 |
+----+--------+
1 row in set (0.00 sec)
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!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete