mysql四种隔离级别与实现方式

目录

一.自己的理解

二.网上的总结

 


一.自己的理解

READ UNCOMMITTED(RU) : 对于修改的项加排它锁,直到事务结束释放;没有快照读,只能读最新版本的数据。

READ COMMITTED(RC) :对于修改的项加排它锁,直到事务结束释放;有快照读,快照的粒度是语句级

REPEATABLE READ(RR) :对于修改的项加排它锁,直到事务结束释放;有快照读,快照的粒度是事务级

SERIALIZABLE : 串行化。

 

二.网上的总结

转自 https://blog.csdn.net/keda8997110/article/details/45080453

InnoDB存储引擎中不同SQL在不同隔离级别下锁比较

隔离级别

        一致性读和锁

SQL

Read Uncommited Read Commited Repeatable Read Serializable
SQL 条件        
select 相等 None locks Consisten read/None lock Consisten read/None lock Share locks
范围 None locks Consisten read/None lock Consisten read/None lock Share Next-Key
update 相等 exclusive locks exclusive locks exclusive locks Exclusive locks
范围 exclusive next-key exclusive next-key exclusive next-key exclusive next-key
Insert N/A exclusive locks exclusive locks exclusive locks exclusive locks
replace 无键冲突 exclusive locks exclusive locks exclusive locks exclusive locks
键冲突 exclusive next-key exclusive next-key exclusive next-key exclusive next-key
delete 相等 exclusive locks exclusive locks exclusive locks exclusive locks
范围 exclusive next-key exclusive next-key exclusive next-key exclusive next-key
Select ... from ... Lock in share mode 相等 Share locks Share locks Share locks Share locks
范围 Share locks Share locks Share Next-Key Share Next-Key
Select * from ... For update 相等 exclusive locks exclusive locks exclusive locks exclusive locks
范围 exclusive locks Share locks exclusive next-key exclusive next-key

Insert into ... Select ...

(指源表锁)

innodb_locks_unsafe_for_binlog=off Share Next-Key Share Next-Key Share Next-Key Share Next-Key
innodb_locks_unsafe_for_binlog=on None locks Consisten read/None lock Consisten read/None lock Share Next-Key

create table ... Select ...

(指源表锁)

innodb_locks_unsafe_for_binlog=off Share Next-Key Share Next-Key Share Next-Key Share Next-Key
innodb_locks_unsafe_for_binlog=on None locks Consisten read/None lock Consisten read/None lock Share Next-Key

 

你可能感兴趣的:(mysql,mysql)