查找原始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 ---------- ...
随机推荐
- 手动部署servlet
1.编写servlet,在tomcat\webapps目录下新建文件Test,Test目录如下 Test | classes web.xml | test01 | Servletfirst.jav ...
- Linux操作系统下搭建LAMP环境
准备:先在目录home/csy/下建website代码目录,然后新建php文件,命名为test.php. 在test.php编写代码如下: <? php phpinfo(); ?> 保存并 ...
- String 与 StringBuffer的区别
String="a" 的方式每相加一次就创建一个新的常量,原常量不消失,比较占内存:StringBuffer是放在堆里面,append直接在原地址相加,不占内存
- C89和C99区别--简单总结
(1)对数组的增强 可变长数组 C99中,程序员声明数组时,数组的维数可以由任一有效的整型表达式确定,包括只在运行时才能确定其值的表达式,这类数组就叫做可变长数组,但是只有局部数组才可以是变长的.可变 ...
- Android菜鸟成长记15 -- BitMap
BitMap简介 Bitmap是Android系统中的图像处理的最重要类之一.用它可以获取图像文件信息,进行图像剪切.旋转.缩放等操作,并可以指定格式保存图像文件.本文从应用的角度,着重介绍怎么用Bi ...
- map集合键值对存储,键值不重复,值可以重复
import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Li ...
- 在GMIC听“移动互联网+医疗”的感受 2015-04-29
“互联网+”这个词挺火的,基本格式是“互联网+传统行业”,比如医疗.教育.交通等等.就更别说电子商务.金融这些领域了,相比已经和互联网分不 开了.在我看来,互联网+的背后,是信息化.智能化.信息沟通的 ...
- 极光推送NotificationServiceTest.appex文件变红不存在丢失解决办法
这个图片是文件丢失的 创建.appex文件 创建.appex文件 把极光demo里面的这两个文件复制粘贴到新的文件件(新创建的文件是 UIViewController类型的所以就把 (Notifica ...
- 编码UTF-8
☯,首先,这并不是图片,这是一个unicode字符,Yin Yang,即阴阳符,码点为U+262F.如果你的浏览器无法显示,可以查看这个链接http://www.fileformat.info/inf ...
- csdn的app打开贴子显示空白?
csdn或者虎扑的app打开贴子显示空白,卸载后重装仍然有同样的问题. 可能是android系统的WebView版本太落后. 打开应用市场,更新WebView就可以解决了.