MySQL死鎖案例二(自增列導致死鎖)
測試環境:MySQL 5.7.26
建立測試表:
create table t2(id int auto_increment,status int default null,primary key(id),unique key(status)); Query OK, 0 rows affected (0.01 sec)
死鎖模擬過程如下:
會話2申請s鎖,等待會話1,會話1申請意向插入鎖,等待會話2。innodb選擇kill掉會話2,並丟擲
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
過程說明:
檢視死鎖日誌:
LATEST DETECTED DEADLOCK ------------------------ 2020-08-21 17:28:12 0x7f38f84d3700 *** (1) TRANSACTION: TRANSACTION 26167492, ACTIVE 17 sec inserting mysql tables in use 1, locked 1 LOCK WAIT 2 lock struct(s), heap size 1136, 1 row lock(s), undo log entries 1 MySQL thread id 208, OS thread handle 139883056465664, query id 3844857 localhost root update insert into t2 values(null,10) *** (1) WAITING FOR THIS LOCK TO BE GRANTED: RECORD LOCKS space id 832 page no 4 n bits 72 index status of table `test`.`t2` trx id 26167492 lock mode S waiting Record lock, heap no 2 PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 4; hex 8000000a; asc ;; 1: len 4; hex 80000001; asc ;; *** (2) TRANSACTION: TRANSACTION 26167469, ACTIVE 28 sec inserting, thread declared inside InnoDB 5000 mysql tables in use 1, locked 1 3 lock struct(s), heap size 1136, 2 row lock(s), undo log entries 2 MySQL thread id 209, OS thread handle 139882660706048, query id 3844926 localhost root update insert into t2 values(null,9) *** (2) HOLDS THE LOCK(S): RECORD LOCKS space id 832 page no 4 n bits 72 index status of table `test`.`t2` trx id 26167469 lock_mode X locks rec but not gap Record lock, heap no 2 PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 4; hex 8000000a; asc ;; 1: len 4; hex 80000001; asc ;; *** (2) WAITING FOR THIS LOCK TO BE GRANTED: RECORD LOCKS space id 832 page no 4 n bits 72 index status of table `test`.`t2` trx id 26167469 lock_mode X locks gap before rec insert intention waiting Record lock, heap no 2 PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 4; hex 8000000a; asc ;; 1: len 4; hex 80000001; asc ;; *** WE ROLL BACK TRANSACTION (1)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30135314/viewspace-2713757/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL死鎖案例一(回滾導致死鎖)MySql
- MySQL死鎖案例分析一(先delete,再insert,導致死鎖)MySqldelete
- mysql insert導致死鎖MySql
- 【MySQL】Merge Index導致死鎖MySqlIndex
- 死鎖案例二
- 【MySQL】死鎖案例之六MySql
- 【MySQL】死鎖案例之七MySql
- 【MySQL】死鎖案例之八MySql
- pthread_once導致死鎖thread
- [20180801]insert導致死鎖.txt
- 故障分析 | MySQL死鎖案例分析MySql
- MySQL:Innodb 一個死鎖案例MySql
- MySQL批量更新死鎖案例分析MySql
- 剖析6個MySQL死鎖案例的原因以及死鎖預防策略MySql
- 死鎖案例分析
- 死鎖案例三
- MySQL 死鎖和鎖等待MySql
- GreatSQL 死鎖案例分析SQL
- MySQL死鎖案例 – Learn. Write. Repeat.MySql
- Mysql 兩階段鎖和死鎖MySql
- mysql行鎖和死鎖檢測MySql
- 面試:什麼是死鎖,如何避免或解決死鎖;MySQL中的死鎖現象,MySQL死鎖如何解決面試MySql
- MySQL死鎖系列-線上死鎖問題排查思路MySql
- MySQL解決死鎖MySql
- MySQL死鎖問題MySql
- MySQL 死鎖解決MySql
- MySQL鎖等待與死鎖問題分析MySql
- MySQL:一個死鎖分析 (未分析出來的死鎖)MySql
- mysql死鎖最佳化MySql
- Mysql如何處理死鎖MySql
- MySQL列印死鎖日誌MySql
- MySQL:死鎖一例MySql
- MySQL 死鎖問題分析MySql
- MySQL:MTS和mysqldump死鎖MySql
- Oracle死鎖一例(ORA-00060),鎖表導致的業務死鎖問題Oracle
- MySQL死鎖系列-常見加鎖場景分析MySql
- mysql同一個事務中update,insert導致死鎖問題分析解決MySql
- MySQL/InnoDB中,樂觀鎖、悲觀鎖、共享鎖、排它鎖、行鎖、表鎖、死鎖概念的理解MySql