Updated on 2023-03-06 GMT+08:00

long_query_time Changes Fail to Be Applied

Scenario

After the value of long_query_time was changed from 0.1s to 0.2s on the console, slow query logs still included slow SQL statements whose execution duration was less than 0.2s.

Possible Causes

Changes to long_query_time on the console take effect globally, but only for new connections. As existing connections continue to use the original value (0.1s in this case), slow SQL queries whose execution duration was less than 0.2s are still reported for existing connections.

This problem is caused by the MySQL engine. Changing any of the parameters that take effect for all databases may also have this problem.

Solution

If you need certain session connections to use the new value, close the session connections and re-establish them.