MySQL死結分析,mysql死結

來源:互聯網
上載者:User

MySQL死結分析,mysql死結
1. 測試描述

環境說明:RHEL 6.4 x86_64 + MySQL 5.5.37,交易隔離等級為RC

測試表:

mysql> show create table t1\G*************************** 1. row ***************************       Table: t1Create Table: CREATE TABLE `t1` (  `a` int(11) NOT NULL DEFAULT '0',  `b` int(11) DEFAULT NULL,  PRIMARY KEY (`a`),  KEY `b` (`b`)) ENGINE=InnoDB DEFAULT CHARSET=utf81 row in set (0.00 sec)

測試表中的資料:

mysql> select * from t1;+----+------+| a  | b    |+----+------+|  1 |    1 ||  3 |    3 ||  5 |    6 |+----+------+3 rows in set (0.01 sec)

2. 測試過程

3. 死結日誌分析此時查詢show engine innodb status\G查看死結資訊,下面只摘取了死結資訊部分,其他的省略。
------------------------LATEST DETECTED DEADLOCK------------------------140824  1:01:24*** (1) TRANSACTION:TRANSACTION 110E, ACTIVE 73 sec starting index read   ## 事務ID=110E,活躍了73smysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 376, 2 row lock(s)  ## 有2個行鎖MySQL thread id 1, OS thread handle 0x7f55ea639700, query id 81 localhost root updating  ## 該事務的線程ID=1delete from t1 where a=1   ## 這是當前事務執行的SQL*** (1) WAITING FOR THIS LOCK TO BE GRANTED:  ## 上面SQL等待的鎖資訊RECORD LOCKS space id 12 page no 3 n bits 80 index `PRIMARY` of table `test`.`t1` trx id 110E lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 32  ## 等待在主鍵上的page num=3上有加一個X鎖(not gap waiting),鎖80 bits 0: len 4; hex 80000001; asc     ;; 1: len 6; hex 00000000110c; asc       ;; 2: len 7; hex 0d000002350084; asc     5  ;; 3: len 4; hex 80000001; asc     ;;*** (2) TRANSACTION:TRANSACTION 110C, ACTIVE 1716 sec starting index read, thread declared inside InnoDB 500  ## 事務ID=110C,活躍了1716smysql tables in use 1, locked 13 lock struct(s), heap size 376, 2 row lock(s), undo log entries 1  ## 3個鎖,2個行鎖,1個undo logMySQL thread id 2, OS thread handle 0x7f563c05e700, query id 82 localhost root updating  ## 該事務的線程ID=2delete from t1 where a=3   ## 這是當前事務執行的SQL*** (2) HOLDS THE LOCK(S):  ## 這個事務持有的鎖資訊RECORD LOCKS space id 12 page no 3 n bits 80 index `PRIMARY` of table `test`.`t1` trx id 110C lock_mode X locks rec but not gapRecord lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 32  ## 在主鍵上的page num=3上已持有一個X鎖(not gap),鎖80 bits 0: len 4; hex 80000001; asc     ;; 1: len 6; hex 00000000110c; asc       ;; 2: len 7; hex 0d000002350084; asc     5  ;; 3: len 4; hex 80000001; asc     ;;*** (2) WAITING FOR THIS LOCK TO BE GRANTED:  ## 同時這個事務還等待的鎖資訊RECORD LOCKS space id 12 page no 3 n bits 80 index `PRIMARY` of table `test`.`t1` trx id 110C lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 4; compact format; info bits 0  ## 同樣等待在主鍵上的page num=3上有加一個X鎖(not gap waiting),鎖80 bits 0: len 4; hex 80000003; asc     ;; 1: len 6; hex 000000000f71; asc      q;; 2: len 7; hex ed0000022f0090; asc     /  ;; 3: len 4; hex 80000003; asc     ;;*** WE ROLL BACK TRANSACTION (1)   ## 這裡選擇復原了事務110E。也就是說,這個死結使用事務110E中的SQL沒有執行,復原了:delete from t1 where a=1而事務110C中的SQL是正常被執行的:delete from t1 where a=3

-- Bosco---- END ----

-------------------------------------------------------------------------------------------------------

著作權,文章允許轉載,但必須以連結方式註明源地址,否則追究法律責任!



mysql 死結:怎解決mysql死結

可直接在mysql命令列執行:show engine innodb status\G;查看造成死結的sql語句,分析索引情況,然後最佳化sql然後show processlist;另外可以開啟慢查詢日誌,linux下開啟需在my.cnf的[mysqld]裡面加上以下內容:
 
mysql中運行了查死結命令,結果如下

沒問題,你使用此語句是何意?
show status顯示的是MYSQL伺服器啟動並執行一些統計資訊。你是最佳化表還是統計東西?
不行重啟一下mysql
 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.