5.11.6. Server Log Maintenance
MySQL Server can create a number of different log files that
make it easy to see what is going on. See
Section 5.11, “MySQL Server Logs”. However, you must clean up these
files regularly to ensure that the logs do not take up too much
When using MySQL with logging enabled, you may want to back up
and remove old log files from time to time and tell MySQL to
start logging to new files. See Section 5.9.1, “Database Backups”.
On a Linux (Red Hat) installation, you can use the
mysql-log-rotate script for this. If you
installed MySQL from an RPM distribution, this script should
have been installed automatically. You should be careful with
this script if you are using the binary log for replication. You
should not remove binary logs until you are certain that their
contents have been processed by all slaves.
On other systems, you must install a short script yourself that
you start from cron (or its equivalent) for
handling log files.
You can force MySQL to start using new log files by using
mysqladmin flush-logs or by using the SQL
A log flushing operation does the following:
If general query logging (
--log) or slow
query logging (
--log-slow-queries) is used,
the server closes and reopens the general query log file or
slow query log file.
If binary logging (
--log-bin) is used, the
server closes the current log file and opens a new log file
with the next sequence number.
The server creates a new binary log file when you flush the
logs. However, it just closes and reopens the general and slow
query log files. To cause new files to be created on Unix,
rename the current logs before flushing them. At flush time, the
server will open new logs with the original names. For example,
if the general and slow query logs are named
mysql-slow.log, you can use a series of
commands like this:
mv mysql.log mysql.old
mv mysql-slow.log mysql-slow.old
At this point, you can make a backup of
mysql-slow.log and then remove them from
On Windows, you cannot rename log files while the server has
them open. You must stop the server and rename them, and then
restart the server to create new logs.