LC1990313 2021-08-01 13:50 采纳率: 0%
浏览 11

关于msql中myisam和innodb锁的疑问

myisam引擎执行的sql:

lock table test_myisam read;

select * from test_myisam where id = 1;

update test_myisam set name ='11' where id =1;

执行update 报错

innodb引擎执行的sql:

set autocommit = false;

select * from student where id = 1 lock in share mode;

select * from student where id = 1 for update;

update student set name ='11' where id =1 ;

上面所有语句都可以正常执行

我的疑问是,同一个session中myisam加上共享锁后执行update,因为有共享锁了所以无法加排它锁报错,那为什么在innodb中我加了共享锁,再加排它锁却不报错呢

  • 写回答

1条回答 默认 最新

  • 咕泡-灰灰老师 2021-08-02 15:59
    关注

    首先,锁是根据索引树来的,如果ID是主键,加了共享锁后,排它锁肯定是阻塞不能更改的!确认下版本以及student表的引擎

    评论

报告相同问题?

问题事件

  • 创建了问题 8月1日