Enabling MySQL Query Logging
MySQL provides a valuable feature for troubleshooting and performance analysis by logging every SQL query received from clients along with its submission timestamp. This article guides you through the process of enabling query logging in MySQL, exploring its availability in different versions and methods of configuration.
MySQL Versions Prior to 5.1.29
In MySQL versions earlier than 5.1.29, query logging can be enabled by adding the following line to the [mysqld] section in /etc/my.cnf:
log = /path/to/query.log
Alternatively, you can enable logging directly from the MySQL console using the command:
SET general_log = 1;
Consult the MySQL documentation for further details: http://dev.mysql.com/doc/refman/5.1/en/query-log.html
MySQL 5.1.29 and Later
With the release of MySQL 5.1.29, the log option was deprecated. To enable logging and specify the log file, use the following lines in my.cnf [mysqld] section:
general_log_file = /path/to/query.log general_log = 1
Alternatively, you can turn on logging from the MySQL console, provided you have specified the log file location elsewhere:
SET global general_log = 1;
Additional Options
MySQL provides additional options to refine query logging behavior:
The above is the detailed content of How Do I Enable MySQL Query Logging in Different Versions?. For more information, please follow other related articles on the PHP Chinese website!