MySQL Query Log

General Query and Slow Query Log

  1. Log Output - MySQL Query Log

    This option determines the destination for general query log and slow query log output. The option value can be given as one or more of the words TABLE, FILE, or NONE. TABLE select logging to the general_log and slow_log tables in the mysql database as a destination. FILE selects logging to log files as a destination. NONE disables logging. If NONE is present in the option value, it takes precedence over any other words that are present. TABLE and FILE can both be given to select to both log output destinations.

    SELECT @@log_output;
    SET GLOBAL log_output = '{TABLE|FILE|NONE}';
  2. General Query Log

    The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.

    SELECT @@general_log;
    SET GLOBAL general_log = {0|1}; -- 0 (or OFF) to disable the log or to 1 (or ON) to enable it
    SET GLOBAL general_log_file='/log/mysql/general/mysql_general.log';
    SELECT * from mysql.general_log;
  3. Slow Query Log

    The slow query log consists of SQL statements that took more than long_query_time seconds to execute and required at least min_examined_row_limit rows to be examined. The minimum and default values of long_query_time are 0 and 10, respectively.

    SELECT @@slow_query_log;
    SET GLOBAL slow_query_log = {0|1}; -- 0 (or OFF) to disable the log or to 1 (or ON) to enable it
    SET GLOBAL slow_query_log_file='/log/mysql/slow_query/mysql_slow_query.log';
    SELECT * from mysql.slow_query_log;


Popular posts from this blog