1

I'm seeing conflicting (or complementary) answers on how to rotate mySQL logs and want to know if each method is sufficient in itself, or if I need to use a combination of both.

One method, suggested here, prescribes these steps:

  1. SET logging OFF
  2. RENAME log file
  3. SET logging ON

Another method, from here, gives these steps:

  1. RENAME the log file
  2. FLUSH LOGS

mySQL documentation mentions all these steps but doesn't make clear whether they're different methods of doing the same thing or all necessary steps of the process. Do I need to FLUSH LOGS and SET logging on/off, or just do one of the two?

jschmitter
  • 121
  • 5

1 Answers1

0

The MySQL docs that you referred said "use any of them". But the following

FLUSH LOGS supports optional modifiers to enable selective flushing of individual logs (for example, FLUSH BINARY LOGS).

A log-flushing operation does the following:

  • If general query logging or slow query logging to a log file is enabled, the server closes and reopens the general query log file or slow query 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.

  • 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.

does not work on Windows for opened files (see How can I rename files and folders in Windows that are in use?, Renaming an open file).

Also, the docs says

SET GLOBAL general_log = 'OFF'; ...

This method works on any platform