鍍金池/ 問答/數(shù)據(jù)庫/ update example set counter=counter+1,請問這

update example set counter=counter+1,請問這句自增語句需要加排他鎖嗎?

是不是需要下面這樣使用事務(wù)加上排他鎖?

select counter from example for update;
update example set counter=counter+1;
回答
編輯回答
尕筱澄

mysql默認(rèn)事務(wù)隔離級別Repeatable Read下,update語句如果沒指定id或唯一索引本身就會(huì)鎖表,否則鎖行,所以不需要顯示加鎖的。

2017年7月24日 00:57