Detailed slow query log settings and tools mysqldumpslow

Outline

mysql slow query log is a log mysql provided, which is used to record the time exceeds the threshold value in mysql statement refers run time exceeds the value long_query_time sql, the slow is recorded in the query log. Long_query_time default value is 10, meaning that the statement on the operation of 10S.
Mysqldumpslow today introduces how to use tools to monitor the slow query log.

First, the slow query log settings

1, to see whether to open the slow query log:
show variables like '%slow_query_log%';
2, profile settings
# Set the slow query threshold, in seconds.
long_query_time=30
slow_query_log = 1 # open sql mysql slow log
log_output = table, File # write log output table, will write the log file, in order to facilitate procedures to statistics, so it is best to write the table
slow_query_log_file=/data/log/slow.log
3, do not restart set slow query:
set global log_output = 'TABLE'; - outputs to the table
set global general_log = on; - open all command logging general_log, all statements: successful and unsuccessful.
set global slow_query_log = on; - turn on slow query sql record slow_log
set global long_query_time = 30; - slow query time limit (in seconds)
set global log_queries_not_using_indexes = ON; - recording of unused index sql statement
--Inquire
select * from mysql.slow_log order by 1; - successful execution: Slow query, and the statement did not use the index
4, the query how many slow query log
show global status like '%Slow_queries%';

Two, mysqldumpslow slow log analysis tool

command:
-s sorted that way
c: visit count
l: lock time
r: return records
al: average lock time
ar: the average number of records accessed
at: the average query time
-t is the top n mean, how many pieces of data returned.
-g can keep up with regular pattern matching, case-insensitive.
Example:
1, to obtain up to 20 recording returned sql
mysqldumpslow -s r -t 20 slow.log
2, the average number of sql get 20 most visited
mysqldumpslow -s ar -t 20 slow.log
3, to obtain a maximum average number of visits, and which contains 20 characters sql mq
mysqldumpslow -s ar -t 20 -g "mq" slow.log
Here tips Died at / usr / bin / mysqldumpslow line 161, <> chunk 8. The error is because there -t 20 this sentence, it is to show 20 records before, but I figured out the slow.log not only a to 20, while there are 20, then continue to traverse, and that process will certainly Died.

Guess you like

Origin www.cnblogs.com/johnnyblog/p/11372398.html