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

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

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

按說select是快照讀,不加鎖的,為何會(huì)被 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.

醉了。。。你咋老邀請(qǐng)我,,翻文檔看看吧
https://dev.mysql.com/doc/ref...

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

鎖定寫

lock table my_table_name write;

的意思是寫鎖定, 獲得寫鎖時(shí),其他會(huì)話讀和寫都不行.

要想讓別的session可以讀, 要用

lock table my_table_name read;

才行(不過這時(shí)你自己也不能寫的!).

lock table my_table_name read;的意思不是不讓讀,恰相反,其他會(huì)話可以讀, 但寫不行.

或者說鎖的級(jí)別是這樣的:

lock table xxxx write > lock table xxxx read

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

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

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

2017年3月16日 10:03