Four characteristics of Mysql things ACID

Source:
Disclaimer: If I violate anyone's rights, please contact me and I will delete it.
Welcome experts to spray me


Transactions have 4 characteristics, namely atomicity, consistency, isolation and durability, referred to as the ACID characteristics of transactions;

1. Atomicity (atomicity)

A transaction is either submitted successfully, or all failed and rolled back. You cannot perform only part of the operations. This is the atomicity of the transaction

Two, consistency (consistency)

The execution of the transaction cannot destroy the integrity and consistency of the database data. Before and after the execution of a transaction, the database must be in a consistent state.

If the database system fails during operation, some transactions are forced to be interrupted before they are completed. Some of the modifications made to the database by these unfinished transactions have been written to the physical database. This means that the database is in an incorrect state. Inconsistent state

Three, isolation (isolation)

Transaction isolation means that in a concurrent environment, concurrent transactions are isolated from each other, and the execution of a transaction cannot be interfered by other transactions. When different transactions operate on the same data concurrently, each transaction has its own completed data space, that is, the internal operations and data used by a transaction are isolated from other concurrent transactions, and the concurrently executed transactions cannot interfere with each other.

In the standard SQL specification, 4 transaction isolation levels are defined. Different isolation levels handle transactions differently, namely: unauthorized reading, authorized reading, repeatable reading and serialization

1. Read Uncommited,

This isolation level allows dirty reads, and its isolation level is the lowest; for example, transaction A and transaction B are performed at the same time, transaction A will increase the value of certain data from 1 to 10 during the entire execution phase, and then perform transaction commit. , Transaction B can see all the intermediate values ​​of this data item during the operation of Transaction A (such as 1 becomes 2, 2 becomes 3, etc.), and the reading of this series of intermediate values ​​is unauthorized reading

2. Authorized reading is also called Read Commited,

Authorized read only allows access to the submitted data. For example, transaction A and transaction B are performed at the same time, and transaction A performs a +1 operation. At this time, transaction B cannot see all the intermediate values ​​of this data item during the operation of transaction A, but can only see the final 10. In addition, if there is a transaction C, which performs a very similar operation to transaction A, except that transaction C adds data items from 10 to 20, transaction B can also read to 20 at this time, that is, authorized reads are allowed to be non-repeatable Read.

3. Repeatable Read

It is to ensure that during the transaction processing, when the same data is read multiple times, its value is consistent with the beginning of the transaction. Therefore, the transaction level prohibits non-repeatable reads and dirty reads, but phantom data may appear. The so-called phantom data refers to the same transaction operation, the same data item is read in the two time periods before and after, and inconsistent results may occur. In the above example, the repeatable read isolation level can ensure that transaction B always reads the data item to 1 during the first transaction operation, but in the next transaction operation, even transaction B (note that although the transaction name is Same, but refers to another transaction operation) Using the same query method, it is possible to read 10 or 20;

4. Serialization

Is the most stringent transaction isolation level, it requires all transactions to be executed serially, that is, transactions can only be processed one by one, and cannot be executed concurrently.

Fourth, durability (durability)

Once the transaction is committed, its changes to the state of the corresponding data in the database will be permanently saved in the database. -Even if there is a system crash or machine downtime, as long as the database can be restarted, it will be able to restore it to the state where the transaction ended successfully

Guess you like

Origin blog.csdn.net/qq_45531729/article/details/111455013