MySQL Extension 4 - Transaction Isolation

basic introduction

When our mysql table is operated by multiple threads or clients at the same time, mysql provides a mechanism that allows different transactions to have isolation when operating data. This ensures data consistency.



Without considering transaction isolation, the following problems may arise:


1) Dirty reads

One client (opening the transaction) will read it, and the other client (opening the transaction) has not committed the modified data.


2) Non-repeatable read (heavy 修改操作)

While the first transaction is not over, another transaction also accesses the same data.

Between two reads of data in the first transaction, due to the modification ( and commit ) of the second transaction, the data read twice by the first transaction may be different.

The data read twice in a transaction is not the same , called yes 不可重复读.


3) Phantom reading | Fake reading (emphasis on 增加和删除操作)

The first transaction modifies data in a table, and this modification involves all rows in the table.

At the same time, the second transaction also modifies ( and commits ) the data in this table by inserting a new row of data into the table.

Then, it will happen later that the user who operates the first transaction finds that there are no modified data rows in the table, as if a hallucination occurred.



Transaction isolation level

write picture description here


Basic syntax:

设置
set session transaction isolation level 级别名

查看
select  @@tx_isolation


Supplementary Instructions

MySQL **The default isolation level is Repeatable Read**. Generally in development, do not change.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324658064&siteId=291194637