InnoDB存储引擎下查看阻塞语句和等待语句

  
  
  
  
  1. SELECT r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, 
  2. r.trx_query waiting_query, b.trx_id blocking_trx_id, b.trx_mysql_thread_id blocking_thread, 
  3. b.trx_query blocking_query 
  4. FROM information_schema.innodb_lock_waits w 
  5. INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id 
  6. INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id; 

 结果如下所示:

  
  
  
  
  1. +----------------+----------------+-----------------------------+-----------------+-----------------+-----------------------------+ 
  2. | waiting_trx_id | waiting_thread | waiting_query               | blocking_trx_id | blocking_thread | blocking_query              | 
  3. +----------------+----------------+-----------------------------+-----------------+-----------------+-----------------------------+ 
  4. | 827            |             12 | select c from T2 for update | 826             |              11 | select b from T2 for update | 
  5. | 827            |             12 | select c from T2 for update | 815             |              10 | select sleep(999)           | 
  6. | 826            |             11 | select b from T2 for update | 815             |              10 | select sleep(999)           | 
  7. +----------------+----------------+-----------------------------+-----------------+-----------------+-----------------------------+ 
等待事务id827 select c from T2 for update被select b from T2 for update和select sleep(999)阻塞; 等待事务id826 select b from T2 for update被select sleep(999)阻塞。

你可能感兴趣的:(sql,mysql,InnoDB,locked)