在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  數(shù)據(jù)庫/ Mysql Innodb:RR級別下 lock table 。。 write為何

Mysql Innodb:RR級別下 lock table 。。 write為何會阻塞另一事務(wù)中的select?

我在一個事務(wù)上運(yùn)行了lock table employees write,然后在另一個事務(wù)上用select語句,沒有for update或者lock in share mode

按說select是快照讀,不加鎖的,為何會被 lock table 。。 write的表鎖阻塞?

回答
編輯回答
青瓷

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...

2018年4月18日 07:10
編輯回答
你的瞳

鎖定寫

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

這里有很詳細(xì)的描述:

https://blog.csdn.net/sunhuaq...

lock table主要的使用場景有兩個:模擬事務(wù)處理或加快批處理時update的速度。
其他情況因?yàn)樵趯憰rInnoDB本身就是事務(wù)型的引擎,不般不需要手工加鎖。

2017年3月16日 10:03