MySQL slow query log and MySQL slow log
Lab environment:
OS X EI Captian + MySQL 5.7
1. Configure MySQL to automatically record slow query logs
View the variable, that is, the configuration information.
show (global) variables like '%slow_query%'
Modify variable:
Set global variable name = Value
Variables related to slow query logs:
Whether to enable the slow query log slow_query_log = OFF long_query_time = 10 maximum time limit. If the time limit is exceeded, record slow_query_log_file =/usr/slow. log File Location log_queries_not_using_indexes = OFF whether to record searches without Indexes
Enable the slow query log first:
Bytes
Modify query time:
Bytes
The remaining two global variables are the default values for log paths and records without indexes.
Ii. View MySQL slow query logs
You can directly view:
vim /usr/local/var/mysql/DyanLideMacBook-Air-slow.log
Bytes
You can also usemysqldumpslow
View slow query logs:
mysqldumpslow -s at -a /usr/local/var/mysql/DyanLideMacBook-Air-slow.log
View helpmysqldumpslow --help
:
Bytes
Translation:
-- Verbose version -- debug debugging -- help-v version-d debugging mode-s ORDER sorting mode al: average lock time ar: average rows sent at: average query time default c: count l: lock time r: rows sent t: query time-r reverse order. The default reverse order of the file-t NUM shows the first N-a. Do not convert the number in SQL to N, converting string to S-l in total time does not subtract lock time