• mysql开启慢查询方法


    mysql5.1.6以上版本支持动态开启慢查询(转)
    2011-04-09 12:25

    MySQL在5.0,5.1和6.0版本中还是做出了很多改进,特别是原来一些动不动要重启的操作,慢慢的都可以在线做了,如果要做企业级数据库,在线操作的支持是必不可少的。
    MySQL有很多种日志,包括error log,general query log,binary log,slow query log等。在以前的版本,这些日志的开启或者关闭,都是需要重启服务器的,而且都是记录到日志文件。从MySQL5.1.6版开始,general query log和slow query log开始支持写到文件或者数据库表两种方式,并且日志的开启,输出方式的修改,都可以在Global级别动态修改。
    如果说日志是写到文件还是表,对我们来说不是那么在乎的话,那么可以动态的开启关闭日志真的可以说是梦寐以求的。特别是slow log query,以前一直在头疼,开启吧,可能影响性能,不开吧,对于一些性能差的SQL又没有其他好用的捕获方式。因为开还是不开,涉及到重启服务的问题。
    如果设置log_output=table的话,则日志结果会记录到名为gengera_log和slow_log的两张表中,这两张表的默认引擎都是CSV,其实就是将日志保存为CSV文件格式了。当然,也可以将这两张表改为MyISAM引擎

    Control the slow query log as follows:

    Before 5.1.6, the slow query log destination is always a file. To enable the log, start mysqld with the --log-slow-queries[=file_name] option.

    As of MySQL 5.1.6, the destination can be a file or a table, or both. Start mysqld with the --log-slow-queries[=file_name] option to enable the slow query log, and optionally use --log-output to specify the log destination (as described in Section 5.2.1, “Selecting General Query and Slow Query Log Output Destinations”).

    As of MySQL 5.1.12, as an alternative to --log-slow-queries, use --slow_query_log[={0|1}] to specify the initial slow query log state. In this case, the default slow query log file name is used. With no argument or an argument of 1, --slow_query_log enables the log. With an argument of 0, this option disables the log.

    As of MySQL 5.1.29, use --slow_query_log[={0|1}] to enable or disable the slow query log, and optionally --slow_query_log_file=file_name to specify a log file name. The --log-slow-queries option is deprecated.

    不解的slow log配置。。。。。

    1:首先配置如下
    log_slow_queries    = /var/log/mysql/mysql-slow.log
    long_query_time = 2
    log-queries-not-using-indexes

    有如下警告

    100510   2:42:59 [Warning] '--log_slow_queries' is deprecated and will be removed in a future release. Please use ''--slow_query_log'/'--slow_query_log_file'' instead.


    2:这次把log_slow_queries 换成slow_query_log
    slow_query_log       = /var/log/mysql/mysql-slow.log
    long_query_time = 2
    log-queries-not-using-indexes

    换成slow_query_log,也有警告
    100510   2:45:30 [Warning] options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log_slow_queries is not set


    这样就让我疑惑,改了slow_query_log ,log-queries-not-using-indexes为什么会报错呢,难道是log-queries-not-using-indexes与log_slow_queries 绑定了?
    其实不然,后仔细阅读手册

    As of MySQL 5.1.29, use --slow_query_log[={0|1}] to enable or disable the slow query log, and optionally --slow_query_log_file=file_name to specify a log file name. The --log-slow-queries option is deprecated
    后把配置改为如下:
    slow_query_log=1
    slow_query_log_file = /var/log/mysql/mysql-slow.log
    long_query_time = 2
    log-queries-not-using-indexes

    警告消除

  • 相关阅读:
    MySql数据库时区异常,java.sql.SQLException: The server time zone value '?й???׼ʱ?' is unrecognized or represents more than one time zone.
    SpringBoot中自定义properties文件配置参数并带有输入提示
    Springboot2.x 集成jsp
    Spring Boot使用AOP实现REST接口简易灵活的安全认证
    Spring Boot使用过滤器和拦截器分别实现REST接口简易安全认证
    Spring Boot使用RestTemplate消费REST服务的几个问题记录
    Spring Boot开发MongoDB应用实践
    Spring Boot定时任务应用实践
    Spring Boot缓存应用实践
    Spring Boot消息队列应用实践
  • 原文地址:https://www.cnblogs.com/cnsanshao/p/2630485.html
Copyright © 2020-2023  润新知