重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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://cqcxhl.com/article/ieicgs.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP