Mysql执行监控工具

Mysql架构分层

Mysql执行监控工具

通过show profile查询sql执行情况

set profiling=1;
select * from table;
show profiles; 查询0.00后的执行时间
show profile; 查询各个步骤执行情况
show profile for query 2; 执行了多个sql,查询指定的sql

https://dev.mysql.com/doc/refman/8.0/en/show-profile.html 官网贴一贴
Mysql执行监控工具

performance_schema

MySQL的performance schema 用于监控MySQL server在一个较低级别的运行过程中的资源消耗、资源等待等情况

–查看performance_schema的属性
mysql> SHOW VARIABLES LIKE ‘performance_schema’;

每个线程的最新监视事件
select * from events_waits_current\G

_history表中记录每个线程应该执行完成的事件信息,但每个线程的事件信息只会记录10条,再多就会被覆盖,*_history_long表中记录所有线程的事件信息,但总记录数量是10000,超过就会被覆盖掉
select thread_id,event_id,event_name,timer_wait from events_waits_history order by thread_id limit 21;

summary表提供所有事件的汇总信息,该组中的表以不同的方式汇总事件数据
SELECT EVENT_NAME,COUNT_STAR FROM events_waits_summary_global_by_event_name ORDER BY COUNT_STAR DESC LIMIT 10;

instance表记录了哪些类型的对象会被检测
select * from file_instances limit 20;

查询哪类sql执行的最多
SELECT DIGEST_TEXT,COUNT_STAR,FIRST_SEEN,LAST_SEEN FROM events_statements_summary_by_digest ORDER BY COUNT_STAR DESC