Transaction and isolation level in Mysql

ACID properties of the transaction

  1. Atomicity (Atomicity) Atomicity means that the transaction is an indivisible unit of work, and the operations in the transaction either all happen or none happen.
  2. Consistency transactions must transform the database from one consistency state to another consistency state.
  3. Isolation (Isolation) The isolation of a transaction means that the execution of a transaction cannot be interfered by other transactions, that is, the internal operations and data used by a transaction are isolated from other concurrent transactions, and each transaction executed concurrently cannot interfere with each other .
  4. Durability (Durability) Durability means that once a transaction is committed, its changes to the data in the database are permanent, and other subsequent operations and database failures should not have any impact on it.

Database concurrency

For multiple transactions running at the same time, when these transactions access the same data in the database, if the necessary isolation mechanism is not adopted, various concurrency problems will be caused:
Dirty read : For two transactions T1, T2, T1 read Fields that have been updated by T2 but have not yet been submitted. After that, if T2 rolls back, the content read by T1 is temporary and invalid.
Non-repeatable read : For two transactions T1, T2, T1 read a field, and then T2 updated the field. After that, T1 reads the same field again, and the value is different.
Phantom read : For two transactions T1, T2, T1 read a field from a table, and then T2 inserts some new rows in the table. Later, if T1 reads the same table again, there will be a few more rows.
Isolation of database transactions: The database system must have the ability to isolate and run various transactions concurrently, so that they will not affect each other and avoid various concurrency problems.
The degree of isolation of a transaction from other transactions is called the isolation level. The database specifies a variety of transaction isolation levels, and different isolation levels correspond to different levels of interference. The higher the isolation level, the better the data consistency, but the weaker the concurrency.

Four isolation levels

The four transaction isolation levels provided by the database:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41134324/article/details/109052286