Mysql 5.5 Method for enabling slow log (log_slow_queries), logslowqueries
1. MySQL 5.5 command line
Copy codeThe Code is as follows:
Set global log_slow_queries = on; # enable slow logs
Set [session | global] long_query_time = 0.2 # set the time. exact millisecond
Set global log_queries_not_using_indexes = on; # set a query without an index.
2. view the log storage format
Mysql> show variables like 'Log _ output ';
This FILE is stored as a FILE.
If it is a TABLE, it is stored in the system TABLE. mysql. slow_log TABLE.
Use set global log_output = 'table'; variable to change
3. view the location where slow log files are stored (when files are stored)
4. Run the mysqldumpslow command to view slow logs.
You can use mysqldumpslow-help to query details.
Parameter description:
-S indicates the sorting method. c, t, l, and r are sorted by the number of records, time, query time, and number of returned records (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.
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