1.基本知识:
mysql> show variables like '%slow%';
+---------------------+--------------------------------------------+
| Variable_name | Value |
+---------------------+--------------------------------------------+
| log_slow_queries | ON |
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /usr/local/mysql55/data/localhost-slow.log |
+---------------------+--------------------------------------------+
mysql> show variables like '%long%';
+---------------------------------------------------+----------+
| Variable_name | Value |
+---------------------------------------------------+----------+
| long_query_time | 6.000000 |
The minimum and default values oflong_query_timeare 0 and 10, respectively. The value can be specified to a resolution of microseconds-long_query_time 的最小值是0-10,从 5.1版本开始可以以微秒记录SQL语句运行时间,之前仅用秒为单位记录。
To specify the initial slow query log state explicitly, use --slow_query_log[={0|1}].
为了显示的制定慢查询日志状态,使用slow_query_log=[0|1]
To specify a log file name, use --slow_query_log_file=file_name. To specify the log destination, use --log-output 【--log-output=[TABLE|FILE|NONE]:This option determines the destination for general query log and slow query log output】
为了指定logfile 文件名,使用--slow_query_log_file=file_name,为了指定慢日志的存放目的地(file or table or disableed ),使用参数--log-output Before 5.1.6, the slow query log destination is always a file.
The older option to enable the slow query log file, --log-slow-queries, is deprecated.
5.1.29版本之前使用启动参数--log-slow-queries(参数 log_slow_queries)
总结:
1,设置 set log-slow-queries=[TABLE|FILE|NONE] ;
2.设置 set slow_query_log_file='/usr/local/mysql55/data/localhost-slow.log'
3.设置 setlog-slow-queries=on|1 【5.1.29之前的版本】 | set slow_query_log=1 ;
4.设置 set long_query_time=XXX;
后续补充……