Simple understanding of MySQL transaction isolation
The principle of transaction is acid. Only the isolation level of serialization is in accordance with the principle of acid. Other isolation levels need to be locked to achieve the principle of acid. To be discussed?
There are 4 types of transaction isolation levels in mysql,
1. Read-uncommitted
When two transactions modify the same data, transaction A reads the uncommitted data of transaction B, which will cause the problem of dirty reading
2. Read-committed
When two transactions modify the same data, transaction A queries in the middle of the two transactions, transaction B modifies and submits the data queried by transaction A, and the data results of transaction A's two queries are inconsistent, resulting in a non-repeatable read
3. Repeatable-read
When two transactions modify the same data, transaction A queries the middle of two queries, transaction B modifies and submits the data queried by transaction A, and the data queried by transaction A is inconsistent, which will cause phantom reading
4. Serialization (serializable)
When two transactions modify the same data, transaction A is in progress, transaction B can only wait for transaction A to complete, and only one transaction at a time
The default isolation level of mysql database is repeatable-read, the default isolation level of other databases is read-committed, the default isolation level of aliyun's mysql database is read-committed
read-committed and repeatable-read can solve the problem of data inconsistency by adding optimistic locking or pessimistic locking