Slow query open and query
- Enable slow query temporarily
set global slow_query_log=1
The default timeout is 10 seconds. - Permanently turn on slow query in
my.cnf
In the file[mysqld]
Set in theslow_query_log=1
And set upslow_query_log_file=xxxx
- Set the slow query threshold
set global long_query_time=5
Set the slow query threshold for 5s. The delay takes effect after you log in again. - Select * from SQL where threshold is exceeded:
show global status like '%slow_queries%'
, you can also view the log file through slow query.
Tool mysqldumpslow
- You can use
mysqldumpslow
Tool to view slow query SQL statements,mysqldumpslow -
:s
: sorting,r
: the reverse,l
: Lock time,g
: Indicates the regular matching mode. -
- Such as:
mysqldumpslow -s r -t 3 /var/lib/mysql/localhost-slow.log
: Gets the three SQL statements that return the most records
- Such as:
-
mysqldumpslow -s c -t 3 /var/lib/mysql/localhost-slow.log
: Obtains the three SQL statements that are accessed the most times