Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report