mysql死锁检测时间_MySQL 8 死锁检测脚本

该博客介绍了如何通过SQL查询来检测MySQL中的死锁情况。它详细解释了使用`information_schema.INNODB_TRX`, `performance_schema.data_lock_waits`, 和 `performance_schema.threads`等表来找出引发死锁的事务状态、开始时间、查询以及阻塞信息。提供的检测脚本可以帮助数据库管理员识别和解决死锁问题。
摘要由CSDN通过智能技术生成

1ac1606094790e7c22a19dbb81f5fb61.png

死锁示意图

111fff9db5fc54e3d54ffbee18c697cd.png

死锁相关的表

information_schema.INNODB_TRX

`performance_schema`.data_lock_waits

`performance_schema`.threads

`performance_schema`.data_locks -- 可不使用

相关说明

-- request 被阻塞的

-- block 引起阻塞的

等效字段

`performance_schema`.threads.PROCESSLIST_ID = `information_schema`.innodb_trx.trx_mysql_thread_id = information_schema.`PROCESSLIST`.id

`performance_schema`.threads.thread_id = `performance_schema`.data_lock_waits.REQUESTING_THREAD_ID

检测脚本

SELECT a.*,c.trx_state as block_trx_state,c.trx_started as block_trx_started,c.trx_query as block_trx_query,c.trx_mysql_thread_id as block_trx_mysql_thread_id,d.thread_id as block_thread_id,d.PROCESSLIST_USER as block_user,d.PROCESSLIST_HOST as block_host

from

(SELECT b.trx_id as req_trx_id,b.trx_state as req_trx_state,b.trx_started as req_trx_started,b.trx_query as req_trx_query,b.trx_mysql_thread_id as req_trx_mysql_thread_id,c.thread_id as req_thread_id,c.PROCESSLIST_USER as req_user,c.PROCESSLIST_HOST as req_host

from `performance_schema`.data_lock_waits a

INNER JOIN information_schema.INNODB_TRX b

on a.REQUESTING_ENGINE_TRANSACTION_ID=b.trx_id and a.REQUESTING_ENGINE_LOCK_ID = b.trx_requested_lock_id

INNER JOIN `performance_schema`.threads c

on a.REQUESTING_THREAD_ID = c.THREAD_ID

) a INNER JOIN `performance_schema`.data_lock_waits b

on a.req_trx_id = b.REQUESTING_ENGINE_TRANSACTION_ID and a.req_thread_id = b.REQUESTING_THREAD_ID

INNER JOIN information_schema.INNODB_TRX c

on b.BLOCKING_ENGINE_TRANSACTION_ID = c.TRX_ID

INNER JOIN `performance_schema`.threads d

on b.BLOCKING_THREAD_ID = d.THREAD_ID

检测结果示意

44e8a53f97808e2f260463d17848b340.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值