David Angel David Angel - 5 months ago 9
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

'ON'
make it
'OFF'
and if it's
'OFF'
make it
'ON'
.

I tried this:

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


but that produces an error.

Answer

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.

Comments