Database transaction problems introduced

First, the basic elements of the transaction (ACID)

  A transaction is a logic processing unit consisting of a set of SQL statements, a transaction with the following four attributes, commonly referred to as transaction ACID properties.

  Atomicity ( A tomicity): refers to the entire database transaction is indivisible unit of work. Only the database in all operations is successful, the entire transaction to be successful; any SQL statement failed to execute a transaction, it has been executed successfully SQL statements must be revoked, the database state should return to the state prior to the enforcement branch.
  Consistency ( C onsistency): refers to the database transaction can not undermine the integrity and consistency on the business logic of the data. For example, bank transfer transaction, regardless of the success or failure of the transaction, should ensure that after the end of the transaction total deposits ACCOUNTS table Tom and Jack is 2000 yuan.
  Isolation ( the I solation): refers to the concurrent environment, when different transactions while manipulating the same data, each transaction has its own full data space.
  Persistent ( D urability): refers to the end as long as the transaction is successful, it updates to the data must be permanently preserved. Even if a system crash occurs, restart the database system, the database can be restored to the state of affairs when a successful conclusion.

Second, the problem of concurrent transactions

  Dirty read : Transaction A transaction B reads the data update and rollback B, then A read data is dirty data

  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 were updated and submitted, resulting in a transaction A reads the same data multiple times, the results are inconsistent.

  Magic Reading : A system administrator will result in the database specific scores for all students from grade ABCDE changed, but the system administrator B would insert a specific record score at this time, when the end of the A system administrator found that there is change a record does not change overnight, just like happened as hallucinations, this is called phantom reads.

  Summary: non-repeatable reads and phantom reads are easily confused, non-repeatable read focused on the modification, phantom reads focused on added or deleted. Solve the problem of non-repeatable read only lock to meet the conditions of the line, the need to solve the phantom read lock table

Three, MySQL transaction isolation level

  

Wizards      
       
       
       
       

 

Guess you like

Origin www.cnblogs.com/jackcto/p/11905089.html