This article mainly introduces how MySQL clears slow query files and generates a new slow query file online. For more information, see
I. Overview
This chapter mainly describes how to generate a new slow query file online when the slow query file is large.
Test Environment: mysql 5.6.21
Step 2
The code is as follows:
SET global slow_query_log = 0
Whether to disable global slow query
The code is as follows:
Show variables like '% query_log % ';
Set a new slow query file
The code is as follows:
SET global slow_query_log_file = '/var/lib/mysql/mysql-slow_new.log'
Enable slow query
The code is as follows:
SET global slow_query_log = 1;
The code is as follows:
Show variables like '% query_log % ';
A new slow query file is generated in the slow query path.
The slow query information is recorded in the new log file,
At this time, we can archive the slow query files before mv.
Restart mysql service
Service mysql restart
The code is as follows:
Show variables like '% query_log % ';
After the mysql service is restarted, the slow log file will be changed to the previous one in my. cnf file, so if you want to restart the service after the slow log file or just set the mysql-slow_new.log, you need to modify the global settings while modifying my. cnf file to ensure that the file is modified after restart.
Summary
Configuring slow queries is helpful for collecting statements with poor performance at ordinary times, and many tools are dedicated to analyzing slow query logs. percona-toolkit is a good tool for analyzing slow queries, if you are not using it, you can check it out.
The above is all the content of this article, hoping to help you learn.