12
返回列表 发新帖
楼主: lanbaibai

如何查看mysql中表的锁定情况

[复制链接]
论坛徽章:
2
2011新春纪念徽章
日期:2011-01-04 10:34:48ITPUB十周年纪念徽章
日期:2011-11-01 16:24:04
11#
发表于 2014-12-26 18:25 | 只看该作者
show engine innodb status可以看到锁信息,但是比较难以读懂,也可以使用innotop工具,它会把show engine innodb status的输出信息图形化展示。

如果是5.5以后的版本,更方便的是查询information_schema,可以用这 2 个脚本:

select count(*) as num_waiting_thread,
       max(timestampdiff(second, x2.trx_wait_started, now())) as max_wait_time,
       x1.trx_mysql_thread_id as blocking_thread,
       p.user as bt_user,
       p.host as bt_host,
       p.command as bt_command,
       p.time as bt_time,
       p.state as bt_state,
       x1.trx_query as bt_query
from information_schema.innodb_lock_waits as w
inner join information_schema.innodb_trx as x1 on x1.trx_id = w.blocking_trx_id
inner join information_schema.innodb_trx as x2 on x2.trx_id = w.requesting_trx_id
left join information_schema.processlist as p on p.id = x1.trx_mysql_thread_id
group by blocking_thread
order by num_waiting_thread desc;



select timestampdiff(second, x2.trx_wait_started, current_timestamp) as wait_time,
       x2.trx_mysql_thread_id as waiting_thread,
       l.lock_table as wt_request_lock,
       x2.trx_query as wt_query,
       x1.trx_mysql_thread_id as blocking_thread,
       p.user as bt_user,
       p.host as bt_host,
       p.command as bt_command,
       p.time as bt_time,
       p.state as bt_state,
       x1.trx_query as bt_query
from information_schema.innodb_lock_waits as w
inner join information_schema.innodb_trx as x1 on x1.trx_id = w.blocking_trx_id
inner join information_schema.innodb_trx as x2 on x2.trx_id = w.requesting_trx_id
inner join information_schema.innodb_locks as l on w.requested_lock_id = l.lock_id
left join information_schema.processlist as p on p.id = x1.trx_mysql_thread_id
order by wait_time desc;

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表