MySQ transaction (transaction isolation level)

  Surprisingly, most database systems do not provide true isolation, but in between correctness and performance make a compromise.

  ANIS SQL and ISO standards developed four standard transaction isolation levels, but few database vendors comply with these standards. For example, Oracle database does not support Read UNCOMMITTED and REPEATABLE READ transaction isolation level.

  SQL standard defines four levels of isolation are:

    READ UNCOMMITTED

    READ COMMITTED

    REPEATABLE READ

    SERIALIZABLE

  InnoDB storage engine is supported by default REPEATABLE READ isolation sector, but the difference is that with the SQL standard, the InnoDB storage engine at REPEATABLE READ transaction isolation level, using Next-Key Lock lock algorithm, so avoid phantom read. This and other database systems is different.

  Month low isolation, the less transaction requests a lock or locks to keep the less time. This is why most database systems default transaction isolation level is READ COMMITTED

  If you want to set the default transaction isolation level in the MySQL database to start, it would need to modify the MySQL configuration file

    [mysqld]    

    transaction-isolation = READ-COMMITTED

  View the current session transaction isolation level, you can use:

    select @@tx_isolation;

  View global transaction isolation level, you can use:

    select @@global.tx_isolation;

  Set the transaction isolation level global / current session:

    set [global] tx_isolation = 'read-committed';

  In SERIALIABLE transaction isolation level, InnoDB storage engine will automatically add to LOCK IN SHARE MODE after each SELECT statement, that is, each read operation plus a shared lock. Therefore, in this transaction isolation level, reading takes up the lock on the consistency of non-locking read does not support them. At this time, the database transaction isolation level SERIALIZABLE in line with the theoretical requirements.

  Because InnoDB storage engine at REPEATABLE READ isolation level can achieve 3-isolation, it is generally not used Serialiable local transaction isolation level. SERIALIABLE transaction isolation level is mainly used for distributed transactions InnoDB storage engine .

  

Guess you like

Origin www.cnblogs.com/huan30/p/12319399.html