MYSQL慢查询日志存储在表中时查询出TOPSQL的脚本

按执行时间使用倒序的方式排序找出 TOP 10 的慢查询SQL
t_slow.sql

use MySQL;
select * from
(select * from slow_log  where start_time >= '2016-08-01 00:00:01'  order by query_time desc) a
limit 10;

mysql -u root -p -e "source t_slow.sql" > t_slow.txt

按锁定时间使用倒序的方式排序找出 TOP 10 的慢查询SQL
l_slow.sql

use mysql;
select * from
(select * from slow_log  where start_time >= '2016-08-01 00:00:01'  order by lock_time desc) a
limit 10;


mysql -u root -p -e "source l_slow.sql" > l_slow.txt


按输出的行数使用倒序的方式排序找出 TOP 10 的慢查询SQL
r_slow.sql

use mysql;
select * from
(select * from slow_log  where start_time >= '2016-08-01 00:00:01'  order by rows_sent desc) a
limit 10;

mysql -u root -p -e "source r_slow.sql" > r_slow.txt


按执行次数使用倒序的方式排序找出 TOP 10 的慢查询SQL
c_slow.sql

use mysql;
select * from
(select sum(query_time),avg(query_time),sum(lock_time),avg(lock_time),
sum(rows_sent),avg(rows_sent),sum(rows_examined),avg(rows_examined),
count(1),sql_text from slow_log  where start_time >= '2016-08-01 00:00:01'
group by sql_text  order by count(1) desc) a
limit 10;

mysql -u root -p -e "source c_slow.sql" > c_slow.txt
当前标题:MYSQL慢查询日志存储在表中时查询出TOPSQL的脚本
网站链接:http://azwzsj.com/article/ieicgs.html