首页 > 数据库 > MySQL > 正文

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

2024-07-24 12:31:58
字体:
来源:转载
供稿:网友
        按执行时间使用倒序的方式排序找出 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;
 
        按执行次数使用倒序的方式排序找出 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

(编辑:武林网)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表