Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何启用MySQL慢速查询日志?_Mysql_Sql - Fatal编程技术网

如何启用MySQL慢速查询日志?

如何启用MySQL慢速查询日志?,mysql,sql,Mysql,Sql,我的MySQL版本详细信息如下 服务器:通过UNIX套接字的本地主机 软件:MySQL 软件版本:5.0.96-community-log-MySQL社区版(GPL) 协议版本:10 如何启用MySQL慢速查询日志?如果您的服务器高于5.1.6,则可以在运行时本身设置慢速查询日志。您必须为其执行此查询 set global log_slow_queries = 1; set global slow_query_log_file = <some file name>; 请参阅:版本5

我的MySQL版本详细信息如下

  • 服务器:通过UNIX套接字的本地主机
  • 软件:MySQL
  • 软件版本:5.0.96-community-log-MySQL社区版(GPL)
  • 协议版本:10

  • 如何启用MySQL慢速查询日志?

    如果您的服务器高于5.1.6,则可以在运行时本身设置慢速查询日志。您必须为其执行此查询

    set global log_slow_queries = 1;
    set global slow_query_log_file = <some file name>;
    
    请参阅:

    版本5.1.6及以上:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    1。进入MySQL shell并运行以下命令:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    设置全局慢速查询日志='ON'

    2。启用任何其他所需选项。以下是一些常见的示例:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    记录预期检索所有行而不是使用索引的查询的详细信息:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    设置慢速查询日志的路径:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    设置记录查询之前需要运行的时间量:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    3。通过进入MySQL shell并运行以下命令确认更改处于活动状态:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    5.1.6以下版本:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
  • 使用您喜爱的文本编辑器编辑/etc/my.cnf文件 vi/etc/my.cnf

  • 在“[mysqld]”部分下添加以下行。请随意将日志文件的路径更新为您想要的任何内容:

    log slow querys=/var/log/mysql/slow query.log

  • 3。根据需要启用其他选项。下面是上面相同的常用示例:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    设置记录查询之前需要运行的时间量:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    记录预期检索所有行而不是使用索引的查询的详细信息:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    4。重新启动MySQL服务:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    5。通过进入MySQL shell并运行以下命令确认更改处于活动状态:

       set global log_queries_not_using_indexes = 'ON'
    
      set global slow_query_log_file ='/var/log/mysql/slow-query.log';
    
       set global long_query_time = 20;
         (default is 10 seconds)
    
    show variables like '%slow%';
    
      `long_query_time=20
      (default is 10 seconds)`
    
     `log-queries-not-using-indexes`
    
    service mysqld restart
    
    show variables like '%slow%';
    
    更新:1

    根据MySQL文档,错误#1193发生在对SQLSTATE使用错误代码时

    Message: Unknown system variable %s
    
    而且,正如您在同一页上看到的,SQLSTATE 99003没有定义

    请参阅此链接:


    Get error#1238-变量'log_slow_querys'是只读变量,因为MySQL版本低于5.1,请检查这一点,从5.6.1开始,
    log_sloq_querys
    替换为
    slow_query_log
    -\1193-未知系统变量'slow_query_log'在“设置全局slow_query_log='ON'”时显示上述错误命令执行完毕phpmyadmin@John,请看我的更新:1答案。当设置查询在记录之前需要运行的时间量时,如果发生错误:错误1232(42000):变量的参数类型不正确,请改为使用:
    set global long\u query\u time=5设置全局长查询时间='20';在mysql中出错,不要引用数字please@N.B.事情是这样的,如果你现在在谷歌搜索,这个问题是第二个结果。生命的转折。。。