更多用法、请咨询 ./mysqldumpslow --help

  从5.1.6版本开始,慢查询日志即可以是个文件,也可以保存在数据库中的指定表

  参数log_output指定了慢查询输出的格式、默认为file、你也可以将它设为table

  参数log_output是动态的、并且是全局的、我们能够在线进行变更

mysql> show variables like 'log_output';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output    | FILE  |
+---------------+-------+
1 row in set (0.00 sec)

mysql> set global log_output='TABLE';
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'log_output';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output    | TABLE |
+---------------+-------+
1 row in set (0.00 sec)

mysql> select sleep(15);
+-----------+
| sleep(15) |
+-----------+
|         0 |
+-----------+
1 row in set (15.02 sec)

mysql> select * from mysql.slow_logG;
*************************** 1. row ***************************
    start_time: 2013-04-14 01:22:29
     user_host: root[root] @ localhost []
    query_time: 00:00:15
     lock_time: 00:00:00
     rows_sent: 1
 rows_examined: 0
            db: test
last_insert_id: 0
     insert_id: 0
     server_id: 1
      sql_text: select sleep(15)
1 row in set (0.00 sec)

  在这个例子里、我设置了睡眠15秒、那么这句SQL会被记录到slow_log表

  需要注意的是,慢查询日志中有可能记录到与用户权限或密码相关的语句,因此慢查询日志文件的保存也要注意安全