The slow log file is small, and more less command is enough. What if slow logs are large? Here we will introduce the MySQL tool mysqldumpslow to help you parse slow logs (you can also skip this article and read manual directly ).
1. Basic use
$ Mysqldumpslow slow. Log> slow. dat
$ More slow. dat
Output Data:
Count: 3 time = 62.67 S (188 s) Lock = 0.00 S (0 s) rows = 1623770.7 (4871312), root [root] @ localhost
Select /*! N SQL _no_cache */* From 'feed _ receive_0287'
Here we can obtain: the number of occurrences of this statement in the full log, average execution time, total execution time, row send, and so on. Example: Select /*! N SQL _no_cache */* From 'feed _ receive_0287 'is executed three times, with an average of 62 seconds each time.
By default, the output result of mysqlslowdump uses N and S to replace the numbers and strings in SQL. For example, the following slow log
Select count (*) as counter from feed_receive f Where F. rated_uid = 21621 and F. suincluded =-1 and F. rater_type = 4 and F. rate =-2 and F. username = "orczhou.com"
Will be abstracted by mysqlslowdump:
Select count (*) as counter from feed_receive f Where F. rated_uid = N and F. suincluded =-N and F. rater_type = N and F. rate =-N and F. username = "S"
To disable this abstraction, you can use the-a parameter.
2. Sorting Parameters
The default output result of mysqlslowdump is sorted by count (number of SQL statements. You can use the following parameter control:
-S t sort by total query time-s at sort by average query time
-S l sort by total locktime-s Al sort by average lock time
-S sort by total row send-S as sort by average row send
-S c is sorted by count ----
For example:
Mysqldumpslow-s at slow. log. Old> slow.2.dat # view logs by average query time
3. Other parameters
-R reverse sorting
-A. Do not abstract numbers and strings into N and S.
-G only analyzes the matched Query
4. Common commands
The following common commands can be combined with the preceding common parameters:
Mysqldumpslow-s t slow. log. Old> slow.1.dat # view logs by query time
Mysqldumpslow-s at slow. log. Old> slow.2.dat # view logs by average query time
Mysqldumpslow-a-s at slow. log. Old> slow.3.dat # sort by average query time without abstracting numbers
Mysqldumpslow-a-s c slow. log. Old> slow.4.dat # Sort installation executions