Mysql查询当前阻塞和被阻塞的sql

 select btrx.trx_id 被阻塞事务id,btrx.trx_wait_started 被阻塞时间, btrx.trx_mysql_thread_id  被阻塞线程id , btrx.trx_query 被阻塞语句,trx.SQL_TEXT 阻塞语句
 from information_schema.INNODB_TRX btrx 
 left join information_schema.innodb_lock_waits bw  on btrx.trx_id=bw.requesting_trx_id 
 left join (select trx.trx_id,  trx.trx_mysql_thread_id , sc.SQL_TEXT from information_schema.INNODB_TRX trx 
 left join performance_schema.threads t on trx.trx_mysql_thread_id =t.processlist_id
 left join performance_schema.events_statements_current sc on sc.thread_id=t.thread_id) trx on bw.blocking_trx_id=trx.trx_id
 WHERE btrx.trx_state='LOCK WAIT'

查询SQL执行进度

select * from INFORMATION_SCHEMA.PROCESSLIST

#获取线程ID
SELECT * FROM performance_schema.threads WHERE PROCESSLIST_ID=34975

#获取查看执行进度  statement_latency 已执行时间 progress当前执行的进度
select * from sys.session where thd_id = '35001';

select p.id PROCESSLIST_ID, t.thread_id thread_id ,t.PROCESSLIST_INFO,s.statement_latency ,s.progress from INFORMATION_SCHEMA.PROCESSLIST p
left join performance_schema.threads t on p.id=t.PROCESSLIST_ID
left join  sys.session  s on s.thd_id=t.thread_id
 

你可能感兴趣的:(mysql,mysql,数据库,database)