加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql dba系统学习(9)slow query log慢查询日志功能

发布时间:2016-08-04 10:18:36 所属栏目:MySql教程 来源:站长网
导读:慢查询日志(不包括获取锁的时间) 1,开启慢查询日志功能 以前的版本中开启慢查询日志功能的参数是--log_slow_queries在my.cnf文件中指定,但是现在新的版本中
慢查询日志(不包括获取锁的时间)

1,开启慢查询日志功能

以前的版本中开启慢查询日志功能的参数是--log_slow_queries在my.cnf文件中指定,但是现在新的版本中用参数--slow_query_log和--slow_query_log_file来指定

slow_query_log=1

slow_query_log_file=/tmp/mysqlslow.log

重新启动mysql

mysql> show variables like "%slow%";

+---------------------+--------------------+

| Variable_name       | Value              |

+---------------------+--------------------+

| log_slow_queries    | ON                 |

| slow_launch_time    | 2                  |

| slow_query_log      | ON                 |

| slow_query_log_file | /tmp/mysqlslow.log |

+---------------------+--------------------+

4 rows in set (0.00 sec)

2,慢查询相关的 参数long_query_time

当查询超过long_query_time指定的时间,那么就会记录在慢查询日志文件中,默认是10秒

mysql> show variables like "%long%";

+--------------------+-----------+

| Variable_name      | Value     |

+--------------------+-----------+

| long_query_time    | 10.000000 |

我们来吧时间调短试试,看看什么变化

mysql> set session long_query_time=1;   调到1秒

Query OK, 0 rows affected (0.00 sec)

mysql> show variables like "%long%";

+--------------------+----------+

| Variable_name      | Value    |

+--------------------+----------+

| long_query_time    | 1.000000 |

| max_long_data_size | 1048576  |

+--------------------+----------+

2 rows in set (0.00 sec)

mysql> use test;

Database changed

mysql> create table t as select * from information_schema.tables;

Query OK, 53 rows affected (0.12 sec)

Records: 53  Duplicates: 0  Warnings: 0

mysql> insert into t  select *  from t;

Query OK, 3392 rows affected (0.11 sec)

Records: 3392  Duplicates: 0  Warnings: 0

这个时候达到了1秒钟了所以就要记录sql语句

mysql> insert into t  select *  from t;

^[[AQuery OK, 6784 rows affected (1.15 sec)

Records: 6784  Duplicates: 0  Warnings: 0

mysql> system more /tmp/mysqlslow.log

/usr/local/mysql/libexec/mysqld, Version: 5.1.70-log (Source distribution). star

ted with:

Tcp port: 3306  Unix socket: /tmp/mysql.sock

Time                 Id Command    Argument

# Time: 130903 18:46:28

# User@Host: root[root] @ localhost []

# Query_time: 1.150157  Lock_time: 0.000205 Rows_sent: 0  Rows_examined: 13568

use test;

SET timestamp=1378205188;

insert into t  select *  from t;

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读