The four major characteristics of Mysql (ACID) and isolation level

1. Four characteristics of transaction (ACID)

ACID:atomicity+consistency+isolation+durability

  1. Atomicity: All operations in the transaction are executed either successfully, and if they fail, all operations are rolled back.
  2. Consistency: The transaction must change the database from one consistency state to another consistency state, such as transfer issues, to ensure that the total amount remains unchanged.
  3. Isolation: When multiple users access the database concurrently, the transactions opened by the database for each user are not interfered by other users' transactions, and multiple concurrent transactions are isolated from each other.
  4. Persistence: Once the transaction is committed, the changes made to the database are permanent.

2. Problems caused by multithreading

When multiple threads begin transaction operations on the database, the database system must be able to perform isolation operations to ensure the accuracy of data obtained by each thread. When the isolation of transactions is not considered, several problems will occur: dirty reads, phantoms Read, non-repeatable

  1. Dirty read: The data of an uncommitted transaction is read during the execution of a transaction. If the uncommitted transaction is rolled back, the data read by the current transaction will be inconsistent with the data in the database.
  2. Non-repeatable read: A transaction needs to read the data in the database multiple times, but during the two reads, another transaction modifies the data, resulting in different data read before and after the current transaction.
  3. Phantom read: When a transaction performs batch modification of data in a certain range in the database, another transaction inserts data into the range, resulting in the newly inserted data not being modified. If the user reads the data in this range, they will find that some of the data has not been modified, like an illusion.

Three, the isolation level of the transaction

Serialization, repeatable read, read submitted, read uncommitted

Serializable(Serialization): Dirty reads, non-repeatable reads, and phantom reads can be avoided .
Repeatable read(Repeatable read): To avoid dirty reads and non-repeatable reads .
Read committed(Read submitted): to avoid the occurrence of dirty reads .
Read uncommitted(Read but not submitted): The lowest level, no guarantee under any circumstances.

Guess you like

Origin blog.csdn.net/Cxf2018/article/details/109333332