1:查看当前版本并设置long_query_time为0.2
mysql> select version(); +------------+ | version() | +------------+ | 5.1.73-log | +------------+ 1 row in set (0.00 sec) mysql> set global long_query_time =0.2; Query OK, 0 rows affected (0.00 sec)
2:另外新建一个连接
mysql> show variables like '%long_query_time%'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 0.200000 | +-----------------+----------+ 1 row in set (0.00 sec) mysql> select sleep(1); +----------+ | sleep(1) | +----------+ | 0 | +----------+ 1 row in set (0.99 sec)
3:系统上查看慢查询日志
[root@used ~]# tail /var/log/mysql-slow.log Time Id Command Argument # Time: 150421 14:59:11 # User@Host: root[root] @ localhost [] # Query_time: 1.000273 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0 SET timestamp=1429599551; select sleep(1);