MySQL has a function to log down and run slow SQL statements. This log is not available by default. To enable this function, modify my. CNF or add some parameters when MySQL is started.
If you modify it in my. CNF, add the following lines:
Long_query_time = 1
Log-Slow-queries =
Log-queries-not-using-Indexes
Long_query_time indicates how long the SQL statement will be logged after execution, which is 1 second.
Log-Slow-queries is set to write logs there, which can be blank. The system will give a default file log-queries-not-using-indexes, which is the SQL statement that records no index is used.
Analysis:
Mysqldumpslow-help:
-S order what to sort by (T, at, l, Al, R, ar etc), 'at' is default
-T num just show the top N queries
-G pattern grep: only consider into ts that include this string
-S is the order, which indicates that the write is not detailed enough. I will try it out, including readingCode, Mainly including
C, T, L, R, and AC, AT, Al, ar are sorted by the number of queries, time, lock time, and number of returned records, respectively, flashback with a added above
-T indicates the Top N, that is, the number of data records returned.
-G. You can write a regular expression matching later. It is case insensitive.
Mysqldumpslow-s C-T 20 host-slow.log
Mysqldumpslow-s r-T 20 host-slow.log
The preceding command shows the 20 most frequently accessed SQL statements and the 20 most returned SQL statements in the record set.
Mysqldumpslow-T 10-s t-G left join host-slow.log
Return the first 10 SQL statements containing the left join according to the time.
Time: 060908 22:17:43
# Query_time: 12 lock_time: 0 rows_sent: 86345 rows_examined: 580963
Q: What are the meanings of slow query logs?
A: 12 million rows are returned for the query. A total of 86345 rows are queried.