•Log contents are accessible through SQL statements. This enables the use of queries that select only those log entries that satisfy specific criteria. For example, to select log contents associated with a particular client (which can be useful for identifying problematic queries from that client), it is easier to do this using a log table than a log file. 

•Logs are accessible remotely through any client that can connect to the server and issue queries (if the client has the appropriate log table privileges). It is not necessary to log in to the server host and directly access the file system. 

The log table implementation has the following characteristics: 

•In general, the primary purpose of log tables is to provide an interface for users to observe the runtime execution of the server, not to interfere with its runtime execution. 

• CREATE TABLE , ALTER TABLE , and DROP TABLE  are valid operations on a log table. For ALTER TABLE  and DROP TABLE , the log table cannot be in use and must be disabled, as described later. 

•By default, the log tables use the CSV  storage engine that writes data in comma-separated values format. For users who have access to the .CSV  files that contain log table data, the files are easy to import into other programs such as spreadsheets that can process CSV input. 

The log tables can be altered to use the MyISAM  storage engine. You cannot use ALTER TABLE  to alter a log table that is in use. The log must be disabled first. No engines other than CSV  or MyISAM  are legal for the log tables. 

Log Tables and “Too many open files”  Errors. If you select TABLE  as a log destination and the log tables use the CSV  storage engine, you may find that disabling and enabling the general query log or slow query log repeatedly at runtime results in a number of open file descriptors for the .CSV  file, possibly resulting in a “Too many open files”  error. To work around this issue, execute FLUSH TABLES  or ensure that the value of open_files_limit  is greater than the value of table_open_cache_instances . 

•To disable logging so that you can alter (or drop) a log table, you can use the following strategy. The example uses the general query log; the procedure for the slow query log is similar but uses the slow_log  table and slow_query_log  system variable. 

SET @old_log_state = @@GLOBAL.general_log; SET GLOBAL general_log = ’OFF’; ALTER TABLE mysql.general_log ENGINE = MyISAM; SET GLOBAL general_log = @old_log_state; 

• TRUNCATE TABLE  is a valid operation on a log table. It can be used to expire log entries. 

• RENAME TABLE  is a valid operation on a log table. You can atomically rename a log table (to perform log rotation, for example) using the following strategy: 

USE mysql; DROP TABLE IF EXISTS general_log2; CREATE TABLE general_log2 LIKE general_log; RENAME TABLE general_log TO general_log_backup, general_log2 TO general_log; 

• CHECK TABLE  is a valid operation on a log table. 

• LOCK TABLES  cannot be used on a log table. 

• INSERT , DELETE , and UPDATE  cannot be used on a log table. These operations are permitted only internally to the server itself. 

• FLUSH TABLES WITH READ LOCK  and the state of the read_only  system variable have no effect on log tables. The server can always write to the log tables. 

