Four characteristics of Mysql transactions (ACID)

Atomicity, consistency, isolation, and durability are often referred to as ACID.
●Atomicity: A transaction is a complete operation. Each step of the transaction (each element) is an indivisible minimum operation unit. Either all of them are executed, or none of them are executed, or all of them are completed, or none of them are completed.
● Consistency: When the transaction is completed, the data must be in a consistent state.
●Isolation: All concurrent transactions that modify data are isolated from each other, which indicates that transactions must be independent and should not depend on or affect other transactions in any way. , you can set the isolation level
● Durability: The durability of a transaction means that regardless of whether the system fails, the results of the transaction are permanent.
Brief description of the four characteristics of transactions:
atomicity
It is an indivisible smallest unit of operation that either succeeds or fails at the same time.
persistence
When a transaction is committed or rolled back, the database will persist the data.
Isolation
between multiple transactions. Independent.
consistency
The total amount of data remains unchanged before and after the transaction operation
isolation level
transaction isolation level
problems will arise
Read Uncommitted _
Dirty read, phantom read, non-repeatable read
Read Committed _
Phantom read, non-repeatable read
Repeatable Read _
non-repeatable read
Serializable _ _
It will not cause any problems, but it is extremely inefficient and will lock the table.
Problems caused by transactions under concurrent circumstances
—Generally, when multiple unit operations are executed concurrently, several problems will occur.
  • The focus of non-repeatable reading is modification: under the same conditions, the data you have read, and you read it again, you will find that the value is different.
  • The focus of phantom reading is on addition or deletion (change in the number of data items). Under the same conditions, the number of records read out for the first and second times is different.
  • A dirty read occurs when one transaction A reads data that has been modified by another transaction B but has not yet been committed. If B rolls back, transaction A reads invalid data. This is similar to a non-repeatable read, but the second transaction does not need to commit. 
Brief description:
  • Dirty read: Transaction A has not yet been committed, and transaction B has read the result of transaction A. (Destroys isolation)
  • Non-repeatable read: In this transaction, transaction A read the data that it has not operated on multiple times, and the results were inconsistent or the records did not exist. (Breaks consistency, update and delete)
  • Phantom read: In this transaction, transaction A read data that it has not operated on multiple times. When it was retrieved for the first time, the record did not exist, but when it was read for the second time, the record appeared. [Breaking consistency, insert)
The transaction itself does not actually contain these four characteristics. We need to use certain means to make this execution unit meet these four characteristics as much as possible. Then we can call him a transaction

* Note: The isolation level becomes more and more secure from small to large, but the efficiency is getting lower and lower.

Database query isolation level: select @@tx_isolation;

Database set isolation level: set global transaction isolation level level string;

                                                             ***个人理解,哪里有错麻烦大佬指点***

Guess you like

Origin blog.csdn.net/weixin_46522803/article/details/132986538