博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
浅谈MySQL慢查询日志及microslow patch(msl patch)
阅读量:4196 次
发布时间:2019-05-26

本文共 4402 字,大约阅读时间需要 14 分钟。

       mysql(包括所有5.*系列,5.1.21之前)的慢查询日志默认是以秒为单位的,可以通过set [session|global] long_query_time=1这个最低也就是可以设置到1秒,对于0.5,0.005之类就无能为力了,这时候可以有microslow patch(msl patch)补丁来完成这一工作,这个功能的好处自然不言而喻.

 

       在mysql5.1.21及以后版本可以通过set [session|global] long_query_time=0.01等来设置记录0.01秒以上的sql语句.

在5.1.6之后系列产品中还有--log-output=[FILE|TABLE|NONE]特性,这个是选择general_log和slow_log的存储方式,文件,数据表,还是不记录,5.1.6-5.1.20默认是数据表(mysql.slow_log表),其余默认是文件.

--log-queries-not-using-indexes也是5.1的新选项,可以没有使用index的sql语句记录到慢查询日志中

--log-slow-admin-statements该命令选项可以将OPTIMIZE TABLE, ANALYZE TABLE, 以及ALTER TABLE 等管理操作写道慢查询日志中.

 

       在5.0系列产品可以通过安装microslow patch(msl patch)来改进慢查询日志.

这些选项可以加在启动命令上也可以记录在my.cnf里面

至于查看日志,可以直接查看也可以使用工具,对于比较多的日志还是日志方便些.常见的工具有mysql自带的mysqldumpslow以及第三方工具mysqlsla等.

 

       msl patch是通过修改mysql源代码的方式来增强mysql的功能,所以只能是源码安装才可以扩展这个功能,其在上有详细介绍(其实英语很简单,嘿嘿)

有篇文章详细说明了microslow patch的安装和使用摘几个选项放在这方便以后查看

 

Configuration

There are several parameters related to slow log you can set with patch applied. All filter-type options work in conjunction meaning that in order for query to be logged it must match long_query_time AND min_examined_row_limit AND log_slow_filter.

log-slow-queries[=name]

Log slow queries to this log file. Defaults logging to hostname-slow.log file. Must be enabled to activate other slow log options.

This is the most important one as it enables the logging. If you don’t specify it in my.cnf file, the remaining part of the configuration will not matter, because the log file won’t be created. This is also the only option which you cannot change at runtime from MySQL console wit SET or SET GLOBAL command.

log_slow_filter=name

Log only the queries that followed certain execution plan. Multiple flags allowed in a comma-separated string. [qc_miss, full_scan, full_join, tmp_table, tmp_table_on_disk, filesort, filesort_on_disk]

It allows you to filter queries logged by execution plan. For example to log only queries doing full table scans you would need to set this to “full_scan”, while in order to get only those which use on-disk temporary storage for intermediate results “tmp_table_on_disk,filesort_on_disk” would be a proper flags set. To clear the filter just assign an empty string “” to this option.

Note: you should put double quotes around the entire string of comma-separated flags.

Can be changed at run time with both SET SESSION and SET GLOBAL.

log_slow_rate_limit=#

Rate limit statement writes to slow log to only those from every (1/log_slow_rate_limit) session.

With high traffic coming to your database, the slow logging may consume a lot of IO bandwidth and the file may grow huge very quickly when logging all the queries. This parameter allows you to get the full sessions logged while doing it only for every n-th of them thus limiting the number of writes to the log.

Note: this feature will fail to work well if your application uses some kind of connection pooling. Rate limiting is disabled for the replication thread.

Can be changed at run time with both SET SESSION and SET GLOBAL.

log_slow_verbosity=name

Choose how verbose the messages to your slow log will be. Multiple flags allowed in a comma-separated string. [microtime, query_plan, innodb]

msl patch currently can log three types of information: query timings, execution plan details and InnoDB engine per-query statistics. With this option you may choose which of those you want to have in your slow log. For example to have microsecond query timing and InnoDB statistics you would need to set this option to “microtime,innodb”.

Note: You should put double quotes around the entire string of comma-separated flags. Currently “microtime” is mandatory meaning you cannot disable it. “innodb” is only available with the patch supporting that feature.

Can be changed at run time with both SET SESSION and SET GLOBAL.

long_query_time=#

Log all queries that have taken more than long_query_time microseconds to execute to file.

This option is standard MySQL, however after you apply the patch, it will no longer take time in seconds. Instead it will want you to specify the number of microseconds.

Can be changed at run time with both SET SESSION and SET GLOBAL.

min_examined_row_limit=#

Don’t log queries which examine less than min_examined_row_limit rows to file.

If you are not interested in queries which scan no more than N rows, you can set this to the desired value.

Can be changed at run time with both SET SESSION and SET GLOBAL.

 

本文来自CSDN博客,转载请标明出处:

你可能感兴趣的文章
解决openstack novnc一段时间后自动挂断登录不上问题,novncproxy dead but pid file exists
查看>>
构建OpenStack的云基础架构:ManageIQ(转)
查看>>
云管理软件 ManageIQ(转)
查看>>
CentOS 7.0,启用iptables防火墙(转)
查看>>
DISCUZ浅析之COOKIE篇
查看>>
实战DDD(Domain-Driven Design领域驱动设计:Evans DDD)
查看>>
SSH中各个框架的作用以及Spring AOP,IOC,DI详解
查看>>
openstack juno 配置vmware(vcenter、vsphere)
查看>>
远程debug调试(eclipse)之openstack windows
查看>>
PAAS平台对比:OpenShift VS CloudFoundry【51CTO调研报告】
查看>>
JAX-RS(java restful实现讲解)(转)
查看>>
Spring MVC与JAX-RS比较与分析
查看>>
openstack官方docker介绍
查看>>
头痛与早餐
查看>>
[转]在ASP.NET 2.0中操作数据::创建一个数据访问层
查看>>
Linux命令之chmod详解
查看>>
【java小程序实战】小程序注销功能实现
查看>>
Java中子类能否继承父类的私有属性和方法
查看>>
JVM内存模型详解
查看>>
(二)Git--工作区和暂存区、管理修改与撤销
查看>>