David Angel David Angel - 1 year ago 54
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download