8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux
Home » Articles » Mysql » Here
MySQL : Managing Log Files
This article describes how to manage (delete or purge) log files associated with MySQL.
Related articles.
Binary Logs
Setting the EXPIRE_LOGS_DAYS
parameter in the "/etc/my.cnf" file can be used to manage old binary log files, but you will probably want to manage them as part of your backup schedule.
One slight complication to this is you should keep the contents of the index file consistent with the contents of the log_bin
directory. This can be done using the PURGE BINARY LOGS
command, but that requires you to know the name of the binary log to purge up to.
PURGE BINARY LOGS TO '<binary-log-name>';
There is an example of how to manage binary logs as part of a backup schedule here.
mysqld.log
The simplest way to maintain the "mysqld.log" file on linux is to use the logrotate
functionality.
Amend "/etc/logrotate.d/mysql" file, making the contents look as follows.
/var/log/mysqld.log { copytruncate 644 mysql mysql daily rotate 7 compress postrotate # Nothing to do here. endscript }
A brief explanation of the settings is shown below.
- The first line indicates the file that should be managed.
- "
copytruncate 644 mysql mysql
" : Rather than moving files, the contents of the current file will be copied to a new file, then the current file will be truncated. This prevents us needing to restart MySQL. The permissions indicate the permissions of the files that are created. - "daily" : This rotation will happen on a daily basis.
- "rotate 7" : Seven days worth of logs will be kept. Amend as necessary.
- "compress" : The resulting rotated files will be compressed.
For more information see:
Hope this helps. Regards Tim...