Mysql (slow-query) quick method for enabling slow log query bitsCN.com
How to quickly enable slow log query in mysql (slow-query)
Mysql has a function to log down and run slow SQL statements. by default, this log does not exist.
Open my. ini, find [mysql], and add
Long_query_time = 2
Log-slow-queries = D:/mysql/logs/slow. log # set to write the log there. it can be blank and the system will
A default file
# Log-slow-queries =/var/youpath/slow. log host_name-slow.log in linux
Log-queries-not-using-indexes
Long_query_time indicates how long the SQL statement is executed (in seconds) and is recorded. here, it is set to 2 seconds.
Log-slow-queries sets the location of the log, which can be null. The system will give a default file
Host_name-slow.log, the generated log is under the mysql data directory
Log-queries-not-using-indexes is a literal query that does not use an index.
The following describes common mysqldumpslow parameters. you can use mysqldumpslow-help to query them in detail.
-S indicates the sorting method. c, t, l, and r indicate the number of records, time, query time, and returned
The number of records is sorted (from large to small). ac, at, al, and ar indicate the corresponding flashback.
-T indicates the top n, that is, the number of previous data records returned.
-G, followed by a regular expression matching mode, which is case insensitive.
The next step is to use mysql's built-in slow query tool mysqldumpslow for analysis (in the bin directory of mysql
), My log file name here is host-slow.log.
List the 10 SQL statements with the maximum number of records
Mysqldumpslow-s c-t 10 host-slow.log
List up to 10 SQL statements that return a record set
Mysqldumpslow-s r-t 10 host-slow.log
Return the first 10 SQL statements containing the left join by time
Mysqldumpslow-s t-t 10-g "left join" host-slow.log
The mysqldumpslow command can be used to obtain various query statements that we need very clearly.
The monitoring, analysis, and optimization of query statements are of great help.
BitsCN.com