本篇文章為大家展示了MySQL臨鍵鎖的使用方法,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了雙塔免費(fèi)建站歡迎大家使用!
1、默認(rèn)情況下,innodb使用臨鍵鎖鎖定記錄。
select ... for update
2、當(dāng)查詢索引包含唯一屬性時(shí),臨鍵鎖將被優(yōu)化并降級(jí)為記錄鎖,即只鎖定索引本身,而不是范圍。
3、不同場(chǎng)景下的臨鍵鎖會(huì)退化。
實(shí)例
事務(wù)1 start transaction; select SLEEP(4); select * from test where age=22 for update; select * from test where age>23 for update; select sleep(20); commit; ************************** 事務(wù)2 start transaction; select sleep(8); select * from test where age=20 for update; select * from test where age=21 for update; select * from test where age=22 for update; select * from test where age=23 for update; commit; ************************************ 事務(wù)執(zhí)行狀態(tài) 事務(wù)1 start transaction > OK > 時(shí)間: 0s select SLEEP(4) > OK > 時(shí)間: 4.001s select * from test where age=22 for update > Affected rows: 0 > 時(shí)間: 0.001s select * from test where age>23 for update > Affected rows: 0 > 時(shí)間: 0.001s select sleep(20) > OK > 時(shí)間: 20s commit > OK > 時(shí)間: 0.001s *********************** 事務(wù)2 start transaction > OK > 時(shí)間: 0.001s select sleep(8) > OK > 時(shí)間: 8s select * from test where age=20 for update > Affected rows: 0 > 時(shí)間: 0.001s select * from test where age=21 for update > Affected rows: 0 > 時(shí)間: 0.001s select * from test where age=22 for update > Affected rows: 0 > 時(shí)間: 14.158s select * from test where age=23 for update > Affected rows: 0 > 時(shí)間: 0.001s commit > OK > 時(shí)間: 0s
上述內(nèi)容就是mysql臨鍵鎖的使用方法,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁題目:mysql臨鍵鎖的使用方法
URL標(biāo)題:http://muchs.cn/article30/jpepso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、自適應(yīng)網(wǎng)站、網(wǎng)站內(nèi)鏈、小程序開發(fā)、搜索引擎優(yōu)化、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)