监控数据,主库有大事物运行,可通过如下命令检查下是哪些相关语句导致。

事务未提交sql

  1. SELECT
  2. it.trx_id AS trx_id,
  3. it.trx_state AS trx_state,
  4. it.trx_started AS trx_started,
  5. it.trx_mysql_thread_id AS trx_mysql_thread_id,
  6. CURRENT_TIMESTAMP - it.trx_started AS RUN_TIME,
  7. pl.USER AS USER,
  8. pl.HOST AS HOST,
  9. pl.db AS db,
  10. pl.time AS trx_run_time,
  11. pl.INFO AS INFO
  12. FROM
  13. information_schema.INNODB_TRX it,
  14. information_schema.PROCESSLIST pl
  15. WHERE
  16. pl.id = it.trx_mysql_thread_id
  17. ORDER BY
  18. RUN_TIME DESC
  19. LIMIT 10;

哪个事务阻塞了另一个事务:

  1. SELECT
  2. r.trx_id waiting_trx_id,
  3. r.trx_mysql_thread_id waiting_thread,
  4. r.trx_query waiting_query,
  5. b.trx_id blocking_trx_id,
  6. b.trx_mysql_thread_id blocking_thread,
  7. b.trx_query blocking_query
  8. FROM
  9. information_schema.innodb_lock_waits w
  10. INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
  11. INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id \G

分类: web

标签:   mysql