MySQL Logging – How to Create Daily Queries Log File on Windows

logginglogrotateMySQLwindows

Has MySQL a daily log rotation system? like Apache that creates daily log files?
I'm having a very hard time to find any good info about this.

Win Server 2008 R2
MySQL 5.1.11

I'm logging all (general) queries and the log file size gets large very quickly. would be nice to divide it on a daily basis.

Best Answer

On Windows, the simplest way to rotate a query log is:

  1. Rename the log file, e.g. rename mysql-query.log mysql-query-old.log
  2. Flush the logs by issuing FLUSH LOGS from a MySQL CLI or mysqladmin flush-logs from Windows. This will cause MySQL to close the file you just renamed and create a new file with the original name.

Note that Step 1 could easily be scripted to append the date, then Step 3 to zip the file, etc.

See http://dev.mysql.com/doc/refman/5.1/en/log-file-maintenance.html

Related Topic