天天看點

MySQL Log SettingMySQL Log Setting

MySQL Log Setting

MySQL has the following logs:

Log Type Description
Error Log Problems encountered starting, running, or stopping mysqld
General Query Log Established client connections and statements received from clients.
Binary Log All statements that change data(also used for replication).
Slow Query Log All queries that took more than 'long query time' seconds to execute or didn't use indexes.

Log control at server startup:

[version >= 5.1.9]

--log-output=FILE --general_log --slow_query_log --general_log_file=/var/log/mysql/general.log --slow_query_log_file=/var/log/mysql/slow.log

[version < 5.1.9]

--log=/var/log/mysql/general.log

Log control at runtime:

Varibale Scope Description
log_output global logging destination
general_log global enable(ON) or disable(OFF) the general log
slow_query_log global enable(ON) or disable(OFF) the slow query log
general_log_file global the log file name
slow_query_log_file global the log file name
sql_log_off session enable(ON) or disable(OFF) the general log

Example:

SET GLOBAL general_log = 'OFF';
SET SESSION sql_log_off = 'ON';           

Log Flush

Log flushing occurs when you issue a FLUSH LOGS statement.