How does mysql enable slow log?
First of all, we need to understand four parameters:
Whether to enable slow log in slow_query_log #. Default is OFF. If enabled, set to ON. Slow_query_log_file # slow query log file storage location. Whether log_queries_not_using_indexes # logs SQL that is not used in the index. Default is OFF. If enabled, it is set to ON. How many seconds does the long_query_time # query take before it is recorded in the log? note that the unit is seconds.
Then execute the statement setting (this method will fail when MySQL is restarted)
Once we know the meaning of the parameters, we can set the parameters we need directly. I am using the global settings here.
SET GLOBAL slow_query_log = 'ON';SET GLOBAL slow_query_log_file =' file path (absolute path); SET GLOBAL log_queries_not_using_indexes = 'ON';SET GLOBAL long_query_time = 1; # it should be noted here that the long_query_time parameter will not take effect until the next session, and the current session query is still the original value.
Finally modify the configuration file (permanent settings)
If you want to restart MySQL without invalidation, you can modify the MySQL configuration file. Add the following statement to the configuration file:
Slow_query_log= "ON" slow_query_log_file= "file path (absolute path)" log_queries_not_using_indexes= "ON" long_query_time=1
It will take effect after reboot.
These are the details of how to open the mysql slow query log. Please pay attention to other related articles for more information.