欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

mysql死鎖記錄

測試環(huán)境: MySQL 5.7.18     RR隔離級別

武陵源網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,武陵源網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為武陵源上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的武陵源做網(wǎng)站的公司定做!

mysql 死鎖記錄

創(chuàng)建表,插入部分測試數(shù)據(jù)

CREATE TABLE yhtest (
 a INT (11) NOT NULL AUTO_INCREMENT,
 b INT (11) DEFAULT NULL,
 c INT (11) DEFAULT NULL,
 PRIMARY KEY (a),
 unique key(b)
) ENGINE = INNODB ;

INSERT INTO yhtest VALUE (1, 1, 1),
(2, 2, 2),
(3, 3, 3),
(4, 4, 4),
(5, 5, 5),
(6, 6, 6),
(7, 7, 7),
(8, 8, 8),
(9, 9, 9),
(10, 10, 10),
(11, 11, 11) ;

操作:

事物1:begin;

事物2:begin;

事物1:delete from yhtest where a=2;    可以執(zhí)行

事物2:delete from yhtest where a=3;    可以執(zhí)行

事物1:delete from yhtest where a=4;     可以執(zhí)行

事物2:delete from yhtest where a=5;    可以執(zhí)行

事物1:insert into yhtest value(2,2,2);     鎖等待,待事物2回滾后,可以執(zhí)行

事物2: insert into yhtest value(3,3,3);    報(bào)出死鎖,回滾,如下:

mysql 死鎖記錄

死鎖日志:

------------------------
LATEST DETECTED DEADLOCK
------------------------
2017-10-27 19:38:00 0x7f4b67932700
*** (1) TRANSACTION:
TRANSACTION 3914, ACTIVE 117 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 6 lock struct(s), heap size 1136, 7 row lock(s), undo log entries 3
MySQL thread id 4, OS thread handle 139961837504256, query id 53 localhost root update
insert into yhtest value(2,2,2)
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 31 page no 4 n bits 80 index b of table `test`.`yhtest` trx id 3914 lock mode S waiting
Record lock, heap no 4 PHYSICAL RECORD: n_fields 2; compact format; info bits 32
0: len 4; hex 80000003; asc     ;;
1: len 4; hex 80000003; asc     ;;

*** (2) TRANSACTION:
TRANSACTION 3919, ACTIVE 93 sec inserting
mysql tables in use 1, locked 1
6 lock struct(s), heap size 1136, 6 row lock(s), undo log entries 3
MySQL thread id 5, OS thread handle 139961836971776, query id 54 localhost root update
insert into yhtest value(3,3,3)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 31 page no 4 n bits 80 index b of table `test`.`yhtest` trx id 3919 lock_mode X locks rec but not gap
Record lock, heap no 4 PHYSICAL RECORD: n_fields 2; compact format; info bits 32
0: len 4; hex 80000003; asc     ;;
1: len 4; hex 80000003; asc     ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 31 page no 4 n bits 80 index b of table `test`.`yhtest` trx id 3919 lock mode S waiting
Record lock, heap no 5 PHYSICAL RECORD: n_fields 2; compact format; info bits 32
0: len 4; hex 80000004; asc     ;;
1: len 4; hex 80000004; asc     ;;

*** WE ROLL BACK TRANSACTION (2)

通過innodb日志可以看出,

事物1執(zhí)行  insert into yhtest value(2,2,2);  時,會等待b列索引b=3 上的S鎖被添加,b=3 這一行因?yàn)楸皇挛?執(zhí)行了 delete from yhtest where a=3;  排他鎖鎖住, S鎖等待正常。

事物2執(zhí)行   insert into yhtest value(3,3,3); 時,可以看出其持有b=3 的X鎖, 等待 b=4 上的S鎖被添加,b=4 這一行 因?yàn)楸皇挛?執(zhí)行了delete from yhtest where a=4; 排他鎖鎖住,S鎖等待, 這時候,事物1和事物2互相等待對方持有的鎖資源,形成回環(huán),死鎖出現(xiàn)

這里事物1 插入(2,2,2) 和事物2插入(3,3,3) 因?yàn)閎列的唯一鍵存在,需要進(jìn)行唯一鍵校驗(yàn),而由于在之前已經(jīng)進(jìn)行了該列刪除,需要通過鎖定下一列判斷b=2 的唯一性,b=3的唯一性,而這兩列的鎖已經(jīng)被對方持有,故出現(xiàn)死鎖。

這種死鎖情況,在RC隔離級別下同樣會出現(xiàn)! 

網(wǎng)站題目:mysql死鎖記錄
分享URL:http://chinadenli.net/article4/poopie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、域名注冊Google、網(wǎng)站改版小程序開發(fā)、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站