码迷,mamicode.com
首页 > 数据库 > 详细

MySQL定位锁争用比较严重的表

时间:2014-09-18 21:56:44      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:des   blog   io   os   ar   for   div   art   sp   

1:查看当前的事务

mysql> SELECT * FROM information_schema.innodb_trx \G

2:查看当前锁定的事务

mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

3:查看当前等锁的事务

mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;

 

SELECT  
    r.trx_id waiting_trx_id,  
    r.trx_mysql_thread_id waiting_thread,  
    TIMESTAMPDIFF(  
        SECOND,  
        r.trx_wait_started,  
        CURRENT_TIMESTAMP  
    ) wait_time,  
    r.trx_query waiting_query,  
    l.lock_table waiting_table_lock,  
    b.trx_id blocking_trx_id,  
    b.trx_mysql_thread_id blocking_thread,  
    SUBSTRING(  
        p. HOST,  
        1,  
        INSTR(p. HOST, ‘:‘) - 1  
    ) blocking_host,  
    SUBSTRING(p. HOST, INSTR(p. HOST, ‘:‘) + 1) blocking_port,  
  
IF (p.COMMAND = ‘Sleep‘, p.TIME, 0) idel_in_trx,  
 b.trx_query blocking_query  
FROM  
    information_schema.INNODB_LOCK_WAITS w  
INNER JOIN information_schema.INNODB_TRX b ON b.trx_id = w.blocking_trx_id  
INNER JOIN information_schema.INNODB_TRX r ON r.trx_id = w.requesting_trx_id  
INNER JOIN information_schema.INNODB_LOCKS l ON w.requested_lock_id = l.lock_id  
LEFT JOIN information_schema. PROCESSLIST p ON p.ID = b.trx_mysql_thread_id  
ORDER BY  
    wait_time DESC;

  

 



MySQL定位锁争用比较严重的表

标签:des   blog   io   os   ar   for   div   art   sp   

原文地址:http://www.cnblogs.com/xiaoit/p/3980027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!