我在一个事务上运行了lock table employees write,然后在另一个事务上用select语句,没有for update或者lock in share mode
按说select是快照读,不加锁的,为何会被 lock table 。。 write的表锁阻塞?
我在一个事务上运行了lock table employees write,然后在另一个事务上用select语句,没有for update或者lock in share mode
按说select是快照读,不加锁的,为何会被 lock table 。。 write的表锁阻塞?
锁定写
lock table my_table_name write;
的意思是写锁定, 获得写锁时,其他会话读和写都不行.
要想让别的session可以读, 要用
lock table my_table_name read;
才行(不过这时你自己也不能写的!).
lock table my_table_name read;
的意思不是不让读,恰相反,其他会话可以读, 但写不行.
或者说锁的级别是这样的:
lock table xxxx write > lock table xxxx read
这里有很详细的描述:
https://blog.csdn.net/sunhuaq...
lock table
主要的使用场景有两个:模拟事务处理或加快批处理时update的速度。
其他情况因为在写时InnoDB本身就是事务型的引擎,不般不需要手工加锁。
4 回答1.8k 阅读✓ 已解决
4 回答1.5k 阅读✓ 已解决
8 回答1.4k 阅读
3 回答1.4k 阅读✓ 已解决
1 回答2.7k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
4 回答2.4k 阅读
The downside to locking the tables is that no session can update a READ-locked table (including the one holding the lock) and no session can access a WRITE-locked table other than the one holding the lock.
醉了。。。你咋老邀请我,,翻文档看看吧
https://dev.mysql.com/doc/ref...