Get the App
SLTechnology News&Howtos  ›  Database  › 

Script for querying TOP SQL when the MYSQL slow query log is stored in a table

Shulou Source: shulou.com Published: 2022-06-01 06:13:44 10月31日 Update

Sort by execution time and use reverse order to find the slow query SQL of TOP 10

T_slow.sql

Use mysql

Select * from

(select * from slow_log where start_time > = '2016-08-01 00 order by query_time desc 01' order by query_time desc) a

Limit 10

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

Sort by lock time in reverse order to find the slow query SQL of TOP 10

L_slow.sql

Use mysql

Select * from

(select * from slow_log where start_time > = '2016-08-01 00 order by lock_time desc 01' order by lock_time desc) a

Limit 10

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

Sort by the number of rows output to find the slow query SQL of TOP 10 in reverse order

R_slow.sql

Use mysql

Select * from

(select * from slow_log where start_time > = '2016-08-01 00 order by rows_sent desc 01' order by rows_sent desc) a

Limit 10

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

Sort the slow query SQL of TOP 10 in reverse order according to the number of execution.

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 0015 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

Tags: Query reverse order mode sort time times output log script middle time storage Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS NVidia Huawei Docker