Database Reference
In-Depth Information
• Write the general and slow query logs to tables in the
mysql
database (the table
names are
general_log
and
slow_log
and cannot be changed):
[mysqld]
log_output=TABLE
general_log=1
slow_query_log=1
• Write the general query log to a file named
query.log
and to the
general_log
table:
[mysqld]
log_output=FILE,TABLE
general_log=1
general_log_file=query.log
The binary log
To enable the binary log, use the
--log-bin
option, optionally specifying the logfile
basename as the option value. The default basename is
host_name
-bin
. The value for
this option is a basename because the server creates binary logfiles in numbered se‐
quence, automatically adding to the basename suffixes of
.000001
,
.000002
, and so forth.
The server advances to the next file in the sequence when it starts, when the logs are
flushed, and when the current file reaches the maximum logfile size (controlled by the
max_binlog_size
system variable). To have the server expire logfiles for you, set the
expire_logs_days
system variable to the age in days at which files become eligible for
removal.
Examples:
• Enable the binary log, writing numbered files in the data directory having names
beginning with
host_name
-bin
:
[mysqld]
log-bin
• Enable the binary log, writing numbered files in the data directory having names
beginning with
binlog
. Additionally, expire logfiles after a week:
[mysqld]
log-bin=binlog
max_binlog_size=4G
expire_logs_days=7
22.4. Rotating or Expiring Logfiles
Problem
Files used for logging grow indefinitely unless managed.