是否有切换 general_log 全局设置 on/off 的查询?

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

我可以简单地通过查询切换 (GLOBAL) 变量的状态吗?也就是说,如果它是 'ON',则它是 'OFF',如果它是 'OFF',则它是 'ON'

我试过这个:

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

但这会产生错误。

试试这个:

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

请注意 @@general_log01(它是 bit 类型)并且在 MySQL 中这些值是 falsetrue 分别。