David Angel David Angel - 4 months ago 7x
SQL Question

Is there a query to toggle the general_log global setting on/off?

Can I simply toggle a (GLOBAL) variable's state with a query? That is, if it's

make it
and if it's
make it

I tried this:

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

but that produces an error.


Try this:

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

Note that @@general_log is either 0 or 1 (it's a bit type) and in MySQL these values are false and true respectively.