David Angel David Angel - 5 months ago 8
MySQL Question

Is there a simple MySQL query to toggle general_log on and off?

I'm wanting to know if I can simply switch a (GLOBAL) variable's state on and of with a query like this:

SET GLOBAL general_log = IF(general_log = 'ON', 'OFF', 'ON')


...but that doesn't seem to work.

Answer

Try this:

set global general_log = if (@@general_log = 0, 'ON', 'OFF')
Comments