免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: flyinweb_cu
打印 上一主题 下一主题

求助:mysql慢查询日志会记录不超过设置值大小的查询日志 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2009-12-11 15:18 |只看该作者
原帖由 cenalulu 于 2009-12-11 15:09 发表


log-queries-not-using-indexes 设置为OFF
低于5s的语句就不会记录了



CREATE TABLE `gamegeneral` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(10) unsigned NOT NULL DEFAULT '0',
  `generalid` int(10) unsigned NOT NULL DEFAULT '0',
...
  PRIMARY KEY (`id`),
  UNIQUE KEY `generalid` (`generalid`),
  KEY `uid` (`uid`,`cityid`),
  KEY `status` (`status`),
  KEY `bname` (`bname`)
) ENGINE=InnoDB AUTO_INCREMENT=14138 DEFAULT CHARSET=utf8

mysql> show index from gamegeneral;               
+-------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table       | Non_unique | Key_name  | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| gamegeneral |          0 | PRIMARY   |            1 | id          | A         |        6663 |     NULL | NULL   |      | BTREE      |         |
| gamegeneral |          0 | generalid |            1 | generalid   | A         |        6663 |     NULL | NULL   |      | BTREE      |         |
| gamegeneral |          1 | uid       |            1 | uid         | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| gamegeneral |          1 | uid       |            2 | cityid      | A         |        3331 |     NULL | NULL   |      | BTREE      |         |
| gamegeneral |          1 | status    |            1 | status      | A         |          35 |     NULL | NULL   |      | BTREE      |         |
| gamegeneral |          1 | bname     |            1 | bname       | A         |        6663 |     NULL | NULL   |      | BTREE      |         |
+-------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
6 rows in set (0.01 sec)

# User@Host: root[root] @ localhost []
# Query_time: 0.005975  Lock_time: 0.000081 Rows_sent: 0  Rows_examined: 6898
SET timestamp=1260515581;
SELECT id,uid,class,health,energy,health_sx,energy_sx FROM gamegeneral WHERE uid>0 and health < health_sx or energy<energy_sx;
这个不知算不逄使用了索引

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
12 [报告]
发表于 2009-12-11 15:18 |只看该作者
原帖由 cenalulu 于 2009-12-11 15:17 发表


5.1 以后精度就是这样的吧?


不知道Lz的version

LZ贴下show variables like 'long_query_time';的结果和mysql的版本号

[ 本帖最后由 ruochen 于 2009-12-11 15:20 编辑 ]

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
13 [报告]
发表于 2009-12-11 15:20 |只看该作者
原帖由 flyinweb_cu 于 2009-12-11 15:18 发表



CREATE TABLE `gamegeneral` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(10) unsigned NOT NULL DEFAULT '0',
  `generalid` int(10) unsigned NOT NULL DEFAULT '0',
...
   ...



用explain看是否使用了index

论坛徽章:
0
14 [报告]
发表于 2009-12-11 15:21 |只看该作者
原帖由 ruochen 于 2009-12-11 15:15 发表
Query_time: 0.000094

打微秒补丁的一般是这样的记录
没打的是下面这样的

Query_time: 4


官方下载的tar包,编译安装的
mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.1.34, for pc-linux-gnu (i686) using  EditLine wrapper

Connection id:          1556275
Current database:       dbname
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.1.34-log Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    utf8
Client characterset:    latin1
Conn.  characterset:    latin1
UNIX socket:            /tmp/mysql.sock
Uptime:                 61 days 22 hours 22 min 52 sec

Threads: 4  Questions: 51237785  Slow queries: 1597832  Opens: 16825  Flush tables: 1  Open tables: 384  Queries per second avg: 9.575
--------------

[ 本帖最后由 flyinweb_cu 于 2009-12-11 15:23 编辑 ]

论坛徽章:
0
15 [报告]
发表于 2009-12-11 15:23 |只看该作者
原帖由 ruochen 于 2009-12-11 15:20 发表



用explain看是否使用了index


explain SELECT id,uid,class,health,energy,health_sx,energy_sx FROM gamegeneral WHERE uid>0 and health < health_sx or energy<energy_sx;
+----+-------------+-------------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table       | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------------+------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | gamegeneral | ALL  | uid           | NULL | NULL    | NULL | 6663 | Using where |
+----+-------------+-------------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
16 [报告]
发表于 2009-12-11 15:27 |只看该作者
原帖由 cenalulu 于 2009-12-11 15:17 发表


5.1 以后精度就是这样的吧?


5.1版本以后就是这样的么?我没注意,没注意看changelog

LZ帖show variables like 'long_query_time';

论坛徽章:
0
17 [报告]
发表于 2009-12-11 15:31 |只看该作者
原帖由 ruochen 于 2009-12-11 15:27 发表


5.1版本以后就是这样的么?我没注意,没注意看changelog

LZ帖show variables like 'long_query_time';

show variables like 'long_query_time';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 5.000000 |
+-----------------+----------+
1 row in set (0.00 sec)

论坛徽章:
9
每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00数据库技术版块每周发帖之星
日期:2016-03-07 16:30:25
18 [报告]
发表于 2009-12-11 15:36 |只看该作者
咋一个简单问题这么复杂了。。。

总结一下:
楼主因为开了log-queries-not-using-indexes,所以slow-log会记录两种语句
1. 执行时间超过5s的语句
2. 所有没用用到索引的语句

楼主的需求:
只记录执行时间超过5s的语句。

解决方案:
在my.cnf 把 log-queries-not-using-indexes 注释掉,或者设置为OFF,然后重启

评分

参与人数 1可用积分 +2 收起 理由
ruochen + 2 我很赞同

查看全部评分

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
19 [报告]
发表于 2009-12-11 15:41 |只看该作者
原帖由 cenalulu 于 2009-12-11 15:36 发表
咋一个简单问题这么复杂了。。。

总结一下:
楼主因为开了log-queries-not-using-indexes,所以slow-log会记录两种语句
1. 执行时间超过5s的语句
2. 所有没用用到索引的语句

楼主的需求:
只记录执行 ...



总结的不错

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
20 [报告]
发表于 2009-12-11 15:43 |只看该作者

回复 #18 cenalulu 的帖子

请问BZ
5.1版本的mysql是已经打了microtime的补丁么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP