查找原始MySQL死锁ID
转载地址:http://yueliangdao0608.blog.51cto.com/397025/1180917
如果遇到死锁了,怎么解决呢?找到原始的锁ID,然后KILL掉一直持有的那个线程就可以了, 但是众多线程,可怎么找到引起死锁的线程ID呢? MySQL 发展到现在,已经非常强大了,这个问题很好解决。 直接从数据字典连查找。
mysql> set @@autocommit=;
Query OK, rows affected (0.00 sec) mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| demo_test |
| t3 |
+----------------+
rows in set (0.00 sec) mysql> select * from t3;
+----+--------+--------+------------+----+----+----+
| id | fname | lname | birthday | c1 | c2 | c3 |
+----+--------+--------+------------+----+----+----+
| | lily19 | lucy19 | -- | | | |
| | lily20 | lucy20 | -- | | | |
+----+--------+--------+------------+----+----+----+
rows in set (0.00 sec) mysql> update t3 set birthday = '2022-02-23' where id = ;
Query OK, row affected (0.00 sec)
Rows matched: Changed: Warnings: mysql> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
| |
+-----------------+
row in set (0.00 sec) mysql>
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| |
+--------------+
row in set (0.00 sec) mysql> update t3 set birthday='2018-01-03' where id = ;
ERROR (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
| |
+-----------------+
row in set (0.00 sec) mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| | root | localhost | NULL | Sleep | | | NULL |
| | root | localhost | NULL | Sleep | | | NULL |
| | root | localhost | test | Sleep | | | NULL |
| | root | localhost | test | Query | | init | show processlist |
| | root | localhost | NULL | Sleep | | | NULL |
+----+------+-----------+------+---------+------+-------+------------------+
rows in set (0.00 sec) mysql> show engine innodb status\G ------------
TRANSACTIONS
------------
Trx id counter
Purge done for trx's n:o < 189323 undo n:o < 0 state: running but idle
History list length
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION , not started
MySQL thread id , OS thread handle 0x7f70a0c98700, query id localhost root init
show engine innodb status
---TRANSACTION , ACTIVE sec starting index read
mysql tables in use , locked
LOCK WAIT lock struct(s), heap size , row lock(s)
MySQL thread id , OS thread handle 0x7f70a0bd5700, query id localhost root updating
update t3 set birthday='2018-01-03' where id =
------- TRX HAS BEEN WAITING SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id page no n bits index `PRIMARY` of table `test`.`t3` trx id lock_mode X waiting
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 00000002e38c; asc ;;
: len ; hex 7e00000d2827c9; asc ~ (' ;;
: len ; hex 6c696c793139; asc lily19;;
: len ; hex 6c7563793139; asc lucy19;;
: len ; hex 8fcc57; asc W;;
: len ; hex ; asc ;;
: len ; hex ; asc ;;
: len ; hex ; asc ;; ------------------
---TRANSACTION , ACTIVE sec
lock struct(s), heap size , row lock(s), undo log entries
MySQL thread id , OS thread handle 0x7f70a0b94700, query id localhost root cleaning up
Trx read view will not see trx with id >= , sees <
mysql> SELECT * FROM information_schema.INNODB_TRX\G
*************************** . row ***************************
trx_id:
trx_state: RUNNING
trx_started: -- ::
trx_requested_lock_id: NULL
trx_wait_started: NULL
trx_weight:
trx_mysql_thread_id:
trx_query: NULL
trx_operation_state: NULL
trx_tables_in_use:
trx_tables_locked:
trx_lock_structs:
trx_lock_memory_bytes:
trx_rows_locked:
trx_rows_modified:
trx_concurrency_tickets:
trx_isolation_level: REPEATABLE READ
trx_unique_checks:
trx_foreign_key_checks:
trx_last_foreign_key_error: NULL
trx_adaptive_hash_latched:
trx_adaptive_hash_timeout:
trx_is_read_only:
trx_autocommit_non_locking:
row in set (0.01 sec) mysql>
原来是线程16忘掉COMMIT了。
查找原始MySQL死锁ID的更多相关文章
- MySQL 死锁问题分析
转载: MySQL 死锁问题分析 线上某服务时不时报出如下异常(大约一天二十多次):"Deadlock found when trying to get lock;". Oh, M ...
- 为什么MySQL死锁检测会严重降低TPS
在大量的客户端,更新数据表的同一行时,会造成数据库的吞吐量大幅降低. 很多数据库的前辈和同行分别通过实验和源码的方法,定位到了罪魁祸首----MySQL死锁检测 实验方式:http://blog.cs ...
- mysql 死锁检查
今天看了一篇关于死锁检查的blog. Advanced InnoDB Deadlock Troubleshooting – What SHOW INNODB STATUS Doesn’t Tell Y ...
- MySQL 死锁日志分析
------------------------ LATEST DETECTED DEADLOCK ------------------------ 140824 1:01:24 *** (1) T ...
- mysql死锁——mysql之四
1.MySQL常用存储引擎的锁机制 MyISAM和MEMORY采用表级锁(table-level locking) BDB采用页面锁(page-level locking)或表级锁,默认为页面锁 In ...
- Mysql死锁问题解决方式 & 聚簇索引、隔离级别等知识
参考了这篇文章:http://www.cnblogs.com/LBSer/p/5183300.html <mysql死锁问题分析> 写的不错. 如果Mysql死锁,会报出: 1.1 死锁 ...
- 一次MySQL死锁问题解决
一次MySQL死锁问题解决 一.环境 CentOS, MySQL 5.6.21-70, JPA 问题场景:系统有定时批量更新数据状态操作,每次更新上千条记录,表中总记录数约为500W左右. 二.错误日 ...
- MySQL死锁案例分析与解决方案
MySQL死锁案例分析与解决方案 现象: 数据库查询: SQL语句分析: mysql. 并发delete同一行记录,偶发死锁. delete from x_table where id=? ...
- MySQL死锁分析一例
Tomcat日志报死锁错误,show innodb status获取死锁信息: ------------------------ LATEST DETECTED DEADLOCK ---------- ...
随机推荐
- SQL Server 数据类型映射
SQL Server 和 .NET Framework 基于不同的类型系统. 例如,.NET Framework Decimal 结构的最大小数位数为 28,而 SQL Server 的 decima ...
- 通过Dockerfile建立.NET Core mvc Image
生成.NET core mvc code docker run -itd microsoft/dotnet:latestdocker psdocker attach containeridmkdir ...
- 完整的 mime type 列表
原文地址:http://blog.csdn.net/zhaoyw2008/article/details/46647723 Suffixes applicable Media type and sub ...
- U-Mail邮件系统六项特色服务铸就金口碑
评价一款邮件系统优劣的标准或许有很多,左右你是否选择某个平台的需求或许有不同,但是U-Mail小编必须提醒你:服务水准不可等闲视之!之所以如此, 这是因为:现代社会垃圾邮件猖獗,病毒层出不穷令人防不胜 ...
- R随笔(2)
1,查看R中的变量模式(对象的数据类型)mode() 2,因子(factor), table()可以获取多个因子的交叉表,可以知道每个因子出现的次数 > g<-c("f&quo ...
- 利用Redis解决Url过长的问题
做网站,接手别人的代码,发现url有时候会过长导致页面直接翻掉. 后来想了一下可以利用redis将太长的地方暂存,加载页面时获取即可. 存Redis: /// <summary> /// ...
- DateTime.Compare用法
DateTime.Compare(t1,t2)比较两个日期大小,排前面的小,排在后面的大,比如:2011-2-1就小于2012-3-2返回值小于零: t1 小于 t2. 返回值等于零 : t1 等于 ...
- fastjson将json字符串转化成bean对象解析出错的检查方法
我的情况是:解析第一层数据成功,解析第二层嵌套的数据失败.如: { "response": { "resultcode": "0", &qu ...
- ZT 螨虫的话就不要跟狗多接触,狗的寄生虫很多,还有草地,
病情分析:过敏是治不好的,只能做到避免接触.指导意见:螨虫的话就不要跟狗多接触,狗的寄生虫很多,还有草地,尤其是狗经常去的地方,草地就是螨虫的传播介质.你是过敏性体质除了被免 过敏性源外,还要增强体质 ...
- svn的安装配置
之前找了一些svn的资料,一直配置不成功.然后找到了这个链接,配置成功了.还可以. http://www.cnblogs.com/zhoulf/archive/2013/02/02/2889949.h ...