How can I enable MySQL's slow query log without restarting MySQL?

前端 未结 8 903
情歌与酒
情歌与酒 2020-11-28 19:44

I followed the instructions here: http://crazytoon.com/2007/07/23/mysql-changing-runtime-variables-with-out-restarting-mysql-server/ but that seems to only set the threshold

相关标签:
8条回答
  • 2020-11-28 19:57

    I think the problem is making sure that MySQL server has the rights to the file and can edit it.

    If you can get it to have access to the file, then you can try setting:
    SET GLOBAL slow_query_log = 1;

    If not, you can always 'reload' the server after changing the configuration file. On linux its usually /etc/init.d/mysql reload

    0 讨论(0)
  • 2020-11-28 19:58

    Try SET GLOBAL slow_query_log = 'ON'; and perhaps FLUSH LOGS;

    This assumes you are using MySQL 5.1 or later. If you are using an earlier version, you'll need to restart the server. This is documented in the MySQL Manual. You can configure the log either in the config file or on the command line.

    0 讨论(0)
  • 2020-11-28 19:59

    For slow queries on version < 5.1, the following configuration worked for me:

    log_slow_queries=/var/log/mysql/slow-query.log
    long_query_time=20
    log_queries_not_using_indexes=YES
    

    Also note to place it under [mysqld] part of the config file and restart mysqld.

    0 讨论(0)
  • 2020-11-28 20:10

    If you want to enable general error logs and slow query error log in the table instead of file

    To start logging in table instead of file:

    set global log_output = “TABLE”;
    

    To enable general and slow query log:

    set global general_log = 1;
    set global slow_query_log = 1;
    

    To view the logs:

    select * from mysql.slow_log;
    select * from mysql.general_log;
    

    For more details visit this link

    http://easysolutionweb.com/technology/mysql-server-logs/

    0 讨论(0)
  • 2020-11-28 20:12

    MySQL Manual - slow-query-log-file

    This claims that you can run the following to set the slow-log file (5.1.6 onwards):

    set global slow_query_log_file = 'path';
    

    The variable slow_query_log just controls whether it is enabled or not.

    0 讨论(0)
  • 2020-11-28 20:12

    This should work on mysql > 5.5

    SHOW VARIABLES LIKE '%long%';

    SET GLOBAL long_query_time = 1;

    0 讨论(0)
提交回复
热议问题