MySQL how to clear slow query file _ MySQL

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.