【摘要】 InnoDB 提供四种隔离级别 READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, and SERIALIZABLE。默认为 REPEATABLE READ可用通过一下命令更高隔离模式:SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;全局更改数据库模式,使用如下命令 –transaction-iso…
InnoDB
提供四种隔离级别READ UNCOMMITTED
,READ COMMITTED
,REPEATABLE READ
, andSERIALIZABLE
。
可用通过一下命令更高隔离模式:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
全局更改数据库模式,使用如下命令
或者更高数据库默认启动参数:
[mysqld]
transaction-isolation = REPEATABLE-READ
transaction-read-only = OFF
查询当前数据库状态:
SELECT @@GLOBAL.transaction_isolation, @@GLOBAL.transaction_read_only;
SELECT @@SESSION.transaction_isolation, @@SESSION.transaction_read_only;
默认:
REPEATABLE READ
This is the default isolation level forInnoDB
.Consistent readswithin the same transaction read thesnapshotestablished by the first read. This means that if you issue several plain (nonlocking)SELECT
statements within the same transaction, theseSELECT
statements are consistent also with respect to each other. SeeSection14.7.2.3, “Consistent Nonlocking Reads”.
Forlocking reads(SELECT
withFOR UPDATE
orLOCK IN SHARE MODE
),UPDATE
, andDELETE
statements, locking depends on whether the statement uses a unique index with a unique search condition or a range-type search condition.
-
For a unique index with a unique search condition,
InnoDB
locks only the index record found, not thegapbefore it. -
For other search conditions,
InnoDB
locks the index range scanned, usinggap locksornext-key locksto block insertions by other sessions into the gaps covered by the range. For information about gap locks and next-key locks,