In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
How to filter out the slow query log from the MYSQL query log and find out the TOP SQL, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
There is only time but no date information in # Time in the MYSQL slow query log. You need to know the specific date of a slow query SQL.
You need the unix_timestamp function to convert the timestamp information in # Time into date information.
Unix_timestamp (datetime= > timestamp)
From_unixtime (timestamp= > datetime)
Mysql > select unix_timestamp ('2021-10-26 17V 30v 00')
+-+
| | unix_timestamp ('2021-10-26 1715-3015) | |
+-+
| | 1451122200 |
+-+
1 row in set (0.10 sec)
Select from_unixtime ('1451122200')
Mysql > select from_unixtime ('1451122200')
+-+
| | from_unixtime ('1451122200') | |
+-+
| | 2021-10-26 17-30-30-00.000000 |
+-+
Filter out the slow query logs from 16:30 to 17:30
Method 1: use timestamp filtering
Mysql > select unix_timestamp ('2021-10-26 17V 30v 00')
+-+
| | unix_timestamp ('2021-10-26 1715-3015) | |
+-+
| | 1451122200 |
+-+
1 row in set (0.00 sec)
Mysql > select unix_timestamp ('2021-10-26 16-30 00')
+-+
| | unix_timestamp ('2021-10-26 1615-3015) | |
+-+
| | 1451118600 |
+-+
1 row in set (0.00 sec)
Sed-n'/ SET timestamp=14511186../,/SET timestamp=14511222../'p QITV0223-slow.log > test3.log
Method 2:
Mysql > select unix_timestamp ('2015-12-26 16-12-26 30 00')
+-+
| | unix_timestamp ('2021-10-26 1615-3015) | |
+-+
| | 1451118600 |
+-+
Sed-n'/ SET timestamp=14511186../,$'p QITV0223-slow.log > test4.log
Mysql > select unix_timestamp ('2021-10-26 17V 30v 00')
+-+
| | unix_timestamp ('2021-10-26 1715-3015) | |
+-+
| | 1451122200 |
+-+
1 row in set (0.00 sec)
-- use gred to navigate to the SQL executed at 17:30 in test4.log, such as locating at line 1085
Grep-n 'SET timestamp=14511222..' QITV0223-slow.log test4.log
1085:SET timestamp=1451122200
-- use sed to filter out the first to 1085 rows of data
Sed-n'1 1085 test3.log > test5.log
Method 3: if all SQL have # TIME entries, use # TIME to filter
Sed-n'/ # Time: 151226 16 Time 30 QITV0223-slow.log... test10.log.
If there is no match for "# Time: 151226 17 virtual 30..", all logs from 16:30 to the end of the slow query log will be filtered out.
For the filtered slow query log, retrieve TOP SQL:
1. Get the 10 TOP SQL with the longest execution time.
Mysqldumpslow-st-T10 test10.log > slow_t_top_sql.txt
two。 Get the 10 TOP SQL with the longest average query time.
Mysqldumpslow-s at-t10 test10.log > slow_at_top_sql.txt
3. Get the 10 TOP SQL with the longest lock time.
Mysqldumpslow-sl-T10 test10.log > slow_l_top_sql.txt
4. Get the 10 TOP SQL with the longest average lock time.
Mysqldumpslow-s al-t10 test10.log > slow_l_top_sql.txt
5. Gets the 10 TOP SQL with the most returned records.
Mysqldumpslow-s r-t10 test10.log > slow_r_top_sql.txt
6. Gets the 10 TOP SQL with the most returned records on average.
Mysqldumpslow-s ar-t10 test10.log > slow_r_top_sql.txt
7. Get the 10 TOP SQL with the most execution times.
Mysqldumpslow-s c-t10 test10.log > slow_r_top_sql.txt
After reading the above, do you know how to filter out the slow query log from the MYSQL query log and find out the TOP SQL? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.