LFool-Notes icon indicating copy to clipboard operation
LFool-Notes copied to clipboard

大佬有个数据库锁的问题没有明白,帮忙解答下。【MySQL加锁实战分析】

Open EastEightAreaBoy opened this issue 3 years ago • 2 comments

【MySQL加锁实战分析】文章中的内容有个我实践下来不太理解。 image 上面是我的表信息。 age是一个普通索引。我执行sql:select * from mvcc-test1 where age = 21 for update;后我理解就不能再插入age是20-30之间的数据了对吧?可是我在单独开一个控制台后执行插入却成功了。

这个是我加锁的命令。

image 这个是我插入的数据。 image

EastEightAreaBoy avatar Jun 09 '23 06:06 EastEightAreaBoy

@EastEightAreaBoy

我的数据库版本是 MySQL 8.0.33

我模拟了一下你的过程,我这边第开启的二个插入事务是被卡住的呀!!

image

LFool avatar Jun 09 '23 07:06 LFool

是我工具的问题,不同的窗口都是同一个事务。 image

EastEightAreaBoy avatar Jun 09 '23 07:06 EastEightAreaBoy