Four characteristics and learning database transaction isolation level

Four characteristics and learning database transaction isolation level

Dian four ACID properties of a transaction

   A (Atomicity Atomicity):

    A transaction is a logical unit of work database, all operations in the transaction either all do or do not do.

  C (Consistency Consistency):

    The results of the implementation of the database transaction must change from one consistent state to another consistent state.

  I (Isolation Isolation):

    Executing the transaction can not be other transactions interference.

  D (permanent Durability):

     Once you have submitted the transaction, change its data in the database should be permanent.

 

Isolation of two Dian affairs

  MySql There are four isolation levels.

   1. Read Uncommitted Read Uncommitted 

  Can read data from one transaction to another uncommitted transactions in, once the transaction is rolled back, just to read the data will no longer exist, this is called a dirty read.

 

  2. Read Committed Read Committed

  To solve the problem of dirty reads, you can set transaction isolation level read committed only data after the transaction is committed, it can be read. 

  Then there may be a problem called "non-repeatable read" in. What do you mean? You open a transaction A, a data read, the transaction has not been submitted during this period. At the same time, another person turned Affairs B, this data modifications and submit the transaction B during this time, you again to read the data in the transaction a, found that the data has changed. you did not do, in the same transaction, this data is changed. this is called unrepeatable read.    

 

  3. Repeatable Read Repeatable Read 

  To solve the problem of non-repeatable read, the database isolation level can be set to "re-read." This is the MySql default transaction isolation level.

  In this case the isolation level, the "phantom read" issue will appear. You open a transaction A, a table read all the data, did not submit during the transaction.

  At the same time, another person turned Affairs B, to this table, insert a piece of data, and commits the transaction B .c In this case, n you read all the data in this table again, h will find more than a piece of data, it will appear that the "illusion", wrong. 

 

  4. serialization Serializable

    Serialization is the highest MySql transaction isolation level. Serializes all transactions executed to avoid phantom read, but inefficient.

 

Learning materials:

  Four properties database and transaction isolation level

 

 

  

Guess you like

Origin www.cnblogs.com/timfruit/p/11494336.html