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 levelmysql> 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)
mysql> start transaction; Query OK, 0 rows affected (0.00 sec)
number
value in both terminalsA
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)
number
in B to 2, but does not commit the transactionmysql> update `order` set number=2; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
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.
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
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
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!