zoukankan      html  css  js  c++  java
  • MySQL找出锁等待

    1.服务器级别的锁等待
    可以通过show processlist看到等待锁的线程id,但是无法知道究竟哪个线程持有锁
    可以通过mysqladmin debug
    相关等待锁的线程以及谁持有锁可以在错误日志中找到
     
    #以下是innodb存储引擎中锁等待以及哪个线程持有锁的查找sql
    SELECT r.trx_id AS waiting_trx_id, r.trx_mysql_thread_id AS waiting_thread, TIMESTAMPDIFF(SECOND, r.trx_wait_started, CURRENT_TIMESTAMP) AS wait_time, r.trx_query AS waiting_query, l.lock_table AS waiting_table_lock, b.trx_id AS blocking_trx_id, b.trx_mysql_thread_id AS blocking_thread, SUBSTRING(p.host,1, INSTR(p.host, ':') -1) AS blocking_host, SUBSTRING(p.host, INSTR(p.host, ':') +1) AS block_port, IF(p.command="Sleep",p.time,0) AS idle_in_trx, b.trx_query AS blcoking_query
    FROM information_schema.innodb_lock_waits AS w
    INNER JOIN information_schema.innodb_trx AS b ON b.trx_id=w.blocking_trx_id
    INNER JOIN information_schema.innodb_trx AS r ON r.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 = b.trx_mysql_thread_id
    ORDER BY wait_time DESC;

    #下面查询显示存储引擎层有多少查询被哪些线程阻塞
    SELECT CONCAT('thread ', b.trx_mysql_thread_id, ' from ',p.host) AS who_blocks, IF (p.command = "Sleep",p.time, 0) AS idle_in_trx, MAX(TIMESTAMPDIFF(SECOND,r.trx_wait_started, NOW())) AS max_wait_time, COUNT(*) AS num_waiters
    FROM information_schema.innodb_lock_waits AS w
    INNER JOIN information_schema.innodb_trx AS b ON b.trx_id = w.blocking_trx_id
    INNER JOIN information_schema.innodb_trx AS r ON r.trx_id = w.requesting_trx_id
    LEFT JOIN information_schema.processlist AS p ON p.id = b.trx_mysql_thread_id
    GROUP BY who_blocks
    ORDER BY num_waiters DESC;
  • 相关阅读:
    delphi调用存储过程
    mysql存储过程中使用事务
    高性能JAVA开发之内存管理
    高效的找出两个List中的不同元素
    The reference to entity "characterEncoding" must end with the ';' delimiter
    Maven的安装、配置及使用入门
    如何在电脑上测试手机网站(全)
    三种常用的js数组去重方法
    oracle ORA-01461 错误 can bind a LONG value only for insert into a LONG column
    windows cmd下netstat查看占用端口号的进程和程序
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/6442061.html
Copyright © 2011-2022 走看看