首页 > 代码库 > 【转载】mysql慢查询

【转载】mysql慢查询

mysql> show variables like long%;     注:这个long_query_time是用来定义慢于多少秒的才算“慢查询”+-----------------+-----------+| Variable_name   | Value     |+-----------------+-----------+| long_query_time | 10.000000 | +-----------------+-----------+1 row in set (0.00 sec)mysql> set long_query_time=1;   注: 我设置了1, 也就是执行时间超过1秒的都算慢查询。Query OK, 0 rows affected (0.00 sec)mysql> show variables like slow%;+---------------------+---------------+| Variable_name       | Value         |+---------------------+---------------+| slow_launch_time    | 2             | | slow_query_log      | ON            |           注:是否打开日志记录| slow_query_log_file | /tmp/slow.log |      注: 设置到什么位置+---------------------+---------------+3 rows in set (0.00 sec)mysql> set global slow_query_log=ON   注:打开日志记录一旦slow_query_log变量被设置为ON,mysql会立即开始记录。/etc/my.cnf   里面可以设置上面MYSQL全局变量的初始值。long_query_time=1slow_query_log_file=/tmp/slow.log

转载自http://www.cnblogs.com/zhenghongxin/p/5417030.html

【转载】mysql慢查询