mysql 事物隔离级别
InnoDB
提供四种隔离级别 READ UNCOMMITTED
, READ COMMITTED
, REPEATABLE READ
, and SERIALIZABLE
。
默认为 REPEATABLE READ
可用通过一下命令更高隔离模式:
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 for InnoDB
. Consistent reads within the same transaction read the snapshot established by the first read. This means that if you issue several plain (nonlocking) SELECT
statements within the same transaction, these SELECT
statements are consistent also with respect to each other. See Section 14.7.2.3, “Consistent Nonlocking Reads”.
For locking reads (SELECT
with FOR UPDATE
or LOCK IN SHARE MODE
), UPDATE
, and DELETE
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 the gap before it. -
For other search conditions,
InnoDB
locks the index range scanned, using gap locks or next-key locks to block insertions by other sessions into the gaps covered by the range. For information about gap locks and next-key locks,
- 点赞
- 收藏
- 关注作者
评论(0)