5.4.6 Server Log Maintenance Server Log Maintenance 1067 As described in Section 5.4, “MySQL Server Logs” , MySQL Server can create several different log files to help you see what activity is taking place. However, you must clean up these files regularly to ensure that the logs do not take up too much disk space. 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 7.2, “Database Backup Methods” . On a Linux (Red Hat) installation, you can use the  mysql-log-rotate  script for log maintenance. If you installed MySQL from an RPM distribution, this script should have been installed automatically. 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 replicas. On other systems, you must install a short script yourself that you start from  cron  (or its equivalent) for handling log files. Binary log files are automatically removed after the server’s binary log expiration period. Removal of the files can take place at startup and when the binary log is flushed. The default binary log expiration period is 30 days. To specify an alternative expiration period, use the  binlog_expire_logs_seconds  system variable. If you are using replication, you should specify an expiration period that is no lower than the maximum amount of time your replicas might lag behind the source. To remove binary logs on demand, use the  PURGE BINARY LOGS  statement (see Section 13.4.1.1, “PURGE BINARY LOGS Statement” ). To force MySQL to start using new log files, flush the logs. Log flushing occurs when you execute a  FLUSH LOGS  statement or a  mysqladmin flush-logs ,  mysqladmin refresh ,  mysqldump --flush-logs , or  mysqldump --master-data  command. See Section 13.7.8.3, “FLUSH Statement” , Section 4.5.2, “mysqladmin — A MySQL Server Administration Program” , and Section 4.5.4, “mysqldump — A Database Backup Program” . In addition, the server flushes the binary log automatically when current binary log file size reaches the value of the  max_binlog_size  system variable. FLUSH LOGS  supports optional modifiers to enable selective flushing of individual logs (for example, FLUSH BINARY LOGS ). See Section 13.7.8.3, “FLUSH Statement” . A log-flushing operation has the following effects: Execution of log-flushing statements or commands requires connecting to the server using an account that has the  RELOAD  privilege. On Unix and Unix-like systems, another way to flush the logs is to send a signal to the server, which can be done by  root  or the account that owns the server process. (See Section 4.10, “Unix Signal Handling in MySQL” .) Signals enable log flushing to be performed without having to connect to the server: •As of MySQL 8.0.19,  SIGUSR1  causes the server to flush the error log, general query log, and slow query log. If you are interested in flushing only those logs,  SIGUSR1  can be used as a more “lightweight” signal that does not have the  SIGHUP  effects that are unrelated to logs. •A  SIGHUP  signal flushes all the logs. However,  SIGHUP  has additional effects other than log flushing that might be undesirable. •If the server was started with the  --log-error  option to cause the error log to be written to a file, the server closes and reopens the log file. •If general query logging or slow query logging to a log file is enabled, the server closes and reopens the log file. •If binary logging is enabled, the server closes the current binary log file and opens a new log file with the next sequence number.