MySQL Empty Slow Query file

Source: Internet
Author: User

Original: MySQL Empty slow Query file

Tags: Configure slow query

Overview

This chapter mainly writes about how to generate a new slow query file online when the slow query file is very large.

Test environment: MySQL 5.6.21

Steps

Configure Slow Query

The default my.cnf file is in the/etc/directory

Vim/etc/my.cnf

#slow_queryslow_query_log = # Open Slow query Slow_query_log_file =/ var /lib/mysql/mysql-slow. Log #设置慢查询路径 Long_query_time = 0.01# Set slow query time

Restart MySQL service to take effect after configuration

Query slow query configuration is successful

Test Slow Query

 Use Information_schema; Select *  from tables;

Statement execution time took: 1.1 seconds, returned 314 rows of records;

View slow query files: Cat Mysql-slow.log

The slow query log file records every day slow query records, each record is a time: the beginning of the record contains the login information, the duration of the query, the time of the lock, the number of rows returned, the number of records scanned, the execution of the statement.

generate slow query log files online

1. Turn off global Slow query

SET Global Slow_query_log=0

Query whether to turn off global slow query

 like ' %query_log% ';

Set up a new slow query file

SET Global slow_query_log_file='/var/lib/mysql/mysql-slow_new.log'

Turn on Slow query

SET Global Slow_query_log=1;
 like ' %query_log% ';

In the slow query path, you can see that a new slow query file has been generated.

The following slow query information is recorded in the new log file,

At this time we can archive the MV previous slow query file.

Restart MySQL Service

Service MySQL Restart

 like ' %query_log% ';

After restarting the MySQL service, the slow log file will be re-converted to the previous file set in My.cnf, so if you want to restart the service after the slow log file or just set the Mysql-slow_ New.log, you will need to modify the global settings while modifying the My.cnf file, which will ensure that the file after the reboot or the previously modified file.

Summary

Configuration slow query for the usual collection of poor performance of the statement is very helpful, there are many tools specifically to analyze the slow query log, where Percona-toolkit is a very good analysis of slow query tools, if not used can go to understand.

If the article is helpful to everyone, please help recommend, thank you!!!

Note:

pursuer.chen

Blog:http://www.cnblogs.com/chenmh

This site all the essays are original, welcome to reprint, but reprint must indicate the source of the article, and at the beginning of the article clearly to the link, otherwise reserves the right to hold responsibility.

Welcome to the exchange of discussions

---restore content ends---

MySQL Empty Slow Query file

Related Article

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.