MySQL clears slow Query files

Source: Internet
Author: User

MySQL clears slow Query files
This chapter describes how to generate a new slow Query file online when the slow Query file is large. Test environment: mysql 5.6.21 step configuration slow query default my. the cnf file is in the/etc/directory vim/etc/my. cnf # slow_queryslow_query_log = 1 # enable slow query slow_query_log_file =/var/lib/mysql/mysql-slow.log # Set the slow query path long_query_time = 0.01 # Set the slow query time after configuration to restart the mysql service to take effect query whether the slow query configuration is successful. Test the slow Query use information_schema; select * from tables; statement execution time spent: 1.1 seconds, returned 314 rows of records; view slow Query file: cat mysql-slow.log slow query log file records every day slow query records, each record starts with Time:. It records the login information, the Time spent in the query, the lock Time, the number of returned rows, the number of scanned records, and the executed statement. Generate a slow query log file online. disable global slow query SET global slow_query_log = 0 check whether global slow query is disabled show variables like '% query_log % '; SET a new slow Query file SET global slow_query_log_file = '/var/lib/mysql/mysql-slow_new.log' enable slow query SET global slow_query_log = 1; show variables like '% query_log %'; A new slow Query file is generated in the slow query path. The slow query information will be recorded in the new log file. At this time, we can archive the slow Query file before mv. Restart mysql service mysql restart 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 statements with poor performance in normal times. There are also many tools dedicated to analyzing slow query logs, percona-toolkit is a good tool for analyzing slow queries.

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.