Can the MySQL general query log be turned on for a single database only?
I'd like to turn on MySQL's general query log for a single database only. By default, it records all statements sent to all databases, resulting in huge log files on servers with many d开发者_JAVA百科atabases.
Is it possible to only record statements sent to a particular database?
The general query log is a global log of all queries executed on a given server, so it is not possible to enable or disable it for a specific schema.
There is a variable called SQL_LOG_OFF
that disables general query logging for a specific connection, which maybe useful for you if you can isolate specific connections that use the schema for which you want to enable/disable the general query log:
SET SQL_LOG_OFF = 1;
Note that this only works for users with SUPER privilege, so it may not be useful for you.
General query is enabled by LOG option, it is a global variable, so you cannot set it for one database. But log size can be decreased; disable logging for the server in the ini-file and if it is possible - enable it using SET command in your scripts (only when you need it).
SET GLOBAL LOG := 1; -- enable log
-- execute queries
SET GLOBAL LOG := 0; -- disable log
精彩评论