What are the transaction isolation levels? What is the default isolation level of MySQL?

What are the transaction isolation levels? What is the default isolation level of MySQL?

The SQL standard defines four isolation levels:
READ-UNCOMMITTED (read uncommitted): the lowest isolation level, allows to read uncommitted data changes, which may cause dirty reads, phantom reads, or non-repeatable reads.

READ-COMMITTED (read committed): Allows to read data that has been committed by concurrent transactions, which can prevent dirty reads, but phantom reads or non-repeatable reads may still occur.

REPEATABLE-READ (repeatable read): The results of multiple reads of the same field are consistent, unless the data is modified by the transaction itself, which can prevent dirty reads and non-repeatable reads, but phantom reads may still occur.

SERIALIZABLE (serializable): The highest isolation level, fully compliant with the ACID isolation level. All transactions are executed one by one, so that there is no interference between transactions, that is, this level can prevent dirty reads, non-repeatable reads, and phantom reads.

Insert picture description here

The
default isolation level supported by the MySQL InnoDB storage engine is REPEATABLE-READ (re- readable ) .
We can use the SELECT @@tx_isolation; command to view
Insert picture description here

It should be noted here: the difference from the SQL standard is that the InnoDB storage engine
uses the Next-Key Lock lock algorithm under the REPEATABLE-READ transaction isolation level,
so it can avoid the generation of phantom reads, which is different from other databases. The system (such as SQL Server) is different.
Therefore, the default isolation level supported by the InnoDB storage engine
is REPEATABLE-READ (rereadable),
which can fully guarantee the isolation requirements of transactions,
that is , it has reached the SQL standard SERIALIZABLE (serializable) isolation level.
Because the lower the isolation level, the fewer locks the transaction requests, so the isolation level of most database systems is READCOMMITTED (read commit content),

But what you need to know is that the InnoDB storage engine uses REPEaaTABLEREAD by default, and there is no performance loss.
The InnoDB storage engine generally uses the SERIALIZABLE (serializable) isolation level in the case of distributed transactions .

Guess you like

Origin blog.csdn.net/m0_51684972/article/details/109922767