MySql transaction isolation level

Several issues should first understand the database encounter in a highly concurrent environment before, and transaction isolation levels:

  1. Dirty Read: Transaction A Transaction B reads the data update and rollback operations B, then A is read dirty data.
  2. Non-repeatable read: Transaction A reads the same data multiple times, in the course of the transaction A transaction B read many times, the data has been updated and submitted, resulting in a transaction A reads the same data multiple times, the results are inconsistent.
  3. Magic Reading: for example, transaction A ABCDE all grades changed the rating from specific scores, but the transaction B is inserted into a specific score at this time, after the end of the last transaction A found that there is a record not change overnight, it seems happened illusion. A transaction is an abstract insert operation transaction B during operation.

Non-repeatable read focused on the modification, focusing on new phantom read or delete. Solve non-repeatable read only lock the rows meet the conditions, the need to solve the phantom read lock table.

MySql transaction isolation level is used to solve this problem.

level Dirty read Non-repeatable read Magic Reading
Uncommitted Read Yes Yes Yes
Read Committed no Yes Yes
Repeatable read no no Yes
Serialization no no no

Uncommitted Read: can not be avoided even dirty read, the data read transaction A transaction B updates but not committed.
Read Committed: dirty read can solve the problem, but at this time if another transaction modifies data, it will cause a non-repeatable read problem.
Repeatable read: dirty reads and solves the problem of non-repeatable read, use more.
Serialization: solve all the problems, but is a table lock, poor performance under high concurrency, rarely used in the actual development.

The default transaction isolation level of the database is repeatable read .

Guess you like

Origin www.cnblogs.com/paulwang92115/p/12189210.html