Mysql中锁的使用场景是什么

一、常见锁类型

Mysql中锁的使用场景是什么
常见锁类型

二、Mysql引擎介绍

show variables like '%storage_engine%';

三、常用引擎间的区别

四、共享锁与排他锁

//共享锁
select * from 表名 lock in share mode

//排他锁
select * from 表名 for update

五、排他锁的实际应用

T1: select * from 表名 lock in share mode //假设还未返回结果

T2: update 表名 set name='autofelix'

六、共享锁的实际应用

T1: select * from table lock in share mode

T2: select * from table lock in share mode

七、死锁的发生

T1: 开启事务,执行查询更新两个操作

     select * from table lock in share mode

     update table set column1='hello'

T2: 开启事务,执行查询更新两个操作

     select * from table lock in share mode

     update table set column1='world'

八、另一种发生死锁的情景

T1: begin
     update table set content='hello' where id=10

T2: begin
     update table set content='world' where id=20

九、死锁的解决方式

T1: begin

     select * from table for update

     update table set content='hello'

T2: begin

     select * from table for update

     update table set content='world'
T1: begin

     select * from table [加更新锁操作]

     update table set content='hello'

T2: begin

     select * from table [加更新锁操作]

     update table set content='world'

十、意向锁和计划锁

十一、乐观锁和悲观锁

update table set num=num-1 where id=10 and version=12
本文转载于:https://www.yisu.com/zixun/722182.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。