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