Home >Database >Mysql Tutorial >How Do I Enable MySQL Query Logging in Different Versions?

How Do I Enable MySQL Query Logging in Different Versions?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-22 06:25:32919browse

How Do I Enable MySQL Query Logging in Different Versions?

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:

  • general_log_slow_queries: Logs only queries that exceed a specified time threshold.
  • general_log_without_index: Logs queries that do not utilize any indexes.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn