根据 INNODB_LOCK_WAITS 找到被锁的线程以及加锁的线程

  1. SELECT
  2. t1.requesting_thread_id,
  3. t1.requesting_query,
  4. trx2.trx_mysql_thread_id AS block_thread_id,
  5. proc2.INFO AS block_query
  6. FROM
  7. (
  8. SELECT
  9. trx1.trx_mysql_thread_id AS requesting_thread_id,
  10. proc1.INFO AS requesting_query,
  11. lock1.blocking_trx_id
  12. FROM
  13. information_schema.INNODB_TRX AS trx1
  14. INNER JOIN information_schema.INNODB_LOCK_WAITS AS lock1 ON trx1.trx_id = lock1.requesting_trx_id
  15. INNER JOIN information_schema.`PROCESSLIST` AS proc1 ON trx1.trx_mysql_thread_id = proc1.ID
  16. ) AS t1
  17. INNER JOIN information_schema.INNODB_TRX AS trx2 ON trx2.trx_id = t1.blocking_trx_id
  18. INNER JOIN information_schema.`PROCESSLIST` AS proc2 ON trx2.trx_mysql_thread_id = proc2.ID