Home  >  Article  >  Database  >  How to Enable MySQL\'s Slow Query Log Without Restarting the Server?

How to Enable MySQL\'s Slow Query Log Without Restarting the Server?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-31 09:58:42688browse

How to Enable MySQL's Slow Query Log Without Restarting the Server?

Configuring MySQL Slow Query Log Without Server Restart

Question:

How can you activate MySQL's slow query log without the need for server restart?

Answer:

Dynamically activating the slow query log feature in MySQL requires specific steps, depending on the MySQL version used.

In MySQL versions 5.1 and later, use the following command:

SET GLOBAL slow_query_log = 'ON';

To prevent sensitive data from being stored in cleartext, execute the following command after enabling the log:

FLUSH LOGS;

Additional Considerations for MySQL 5.0:

Prior to MySQL 5.1, server restart was necessary to enable slow query logging. However, you can change the 'log_slow_queries' variable using 'SET GLOBAL' in MySQL 5.0, but it will display a "read-only variable" error.

Refer to MySQL documentation for configurations and log file location details:

  • Config File: Edit the "my.cnf" file and add "slow_query_log" within the [mysqld] section (requires server restart).
  • Command Line: Use "mysqld --log-slow-queries" during server startup.

The above is the detailed content of How to Enable MySQL\'s Slow Query Log Without Restarting the Server?. 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