0

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.

Johan Larsson
  • 87
  • 2
  • 12

1 Answers1

1

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

dartonw
  • 590
  • 2
  • 9
  • I've automated this before with Windows Script Host/JavaScript, and more recently used PowerShell/C# to automate similar tasks. Both have worked flawlessly in production. – dartonw Jul 24 '13 at 02:04
  • I'm doing it that way today, I thought there may be a built-in feature that I don't know about. However, Thank you. – Johan Larsson Jul 24 '13 at 08:51
  • I've searched for such a thing before (and in answering this) and came up empty. Since the process described is officially recommended for all 5.x, this is probably as close to built-in as we will see. – dartonw Jul 24 '13 at 16:25