By default, all logs are disabled or written into files. The general query log and the slow query log can also be written to special tables in the
mysql database. During the startup, entries will always be written into files.
Note that EXPLAIN output will only be recorded if the slow query log is written to a file and not to a table.
To write logs into tables, the log_output server system variable is used. Allowed values are
NONE. It is possible to specify multiple values, separated with commas, to write the logs into both tables and files.
NONE disables logging and has precedence over the other values.
So, to write logs into tables, one of the following settings can be used:
SET GLOBAL log_output = 'TABLE'; SET GLOBAL log_output = 'FILE,TABLE';
The general log will be written into the general_log table, and the slow query log will be written into the slow_log table. Only a limited set of operations are supported for those special tables. For example, direct DML statements (like
INSERT) on those tables will fail with an error similar to the following:
ERROR 1556 (HY000): You can't use locks with log tables.
To empty the contents of the log tables, TRUNCATE TABLE can be used.
The log tables use the CSV storage engine by default. This allows an external program to read the files if needed: normal CSV files are stored in the
mysql subdirectory, in the data dir. However that engine is slow because it does not support indexes, so you can convert the tables to MyISAM (but not other storage engines). To do so, first temporarily disable logging:
SET GLOBAL general_log = 'OFF'; ALTER TABLE mysql.general_log ENGINE = MyISAM; ALTER TABLE mysql.slow_log ENGINE = MyISAM; SET GLOBAL general_log = @old_log_state;
The contents of the log tables is not logged in the binary log thus cannot be replicated.
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.