MySQL slow query log (slow_query_log_file) Switch

Source: Internet
Author: User
Tags mysql slow query log
The slow_query_log_file log becomes very large and it is inconvenient to analyze its input items. We want to generate a slow_query_log_file file every day and analyze this file every day.

The slow_query_log_file log becomes very large and it is inconvenient to analyze its input items. We want to generate a slow_query_log_file file every day and analyze this file every day.

The slow_query_log_file log becomes very large and it is inconvenient to analyze its input items. We want to generate a slow_query_log_file file every day and analyze the log file every day. How to cut by day? We have come up with such a way to switch the log format to this form of hostname-slow _ date. log, the default format is hostname-slow.log. So how to implement it? It is actually very simple. Use the default mysql command.

Mysql> show variables like '% query % log % ';
+ --------------------- + ------------------------------------------ +
| Variable_name | Value |
+ --------------------- + ------------------------------------------ +
| Slow_query_log | OFF |
| Slow_query_log_file |/usr/local/mysql/data/aeolus1-slow.log |
+ --------------------- + ------------------------------------------ +

Mysql> set global slow_query_log_file = '/usr/local/mysql/data/aeolus1-slow_2013-07-19.log ';
Query OK, 0 rows affected (0.03 sec)

Mysql> show variables like '% query % log % ';
+ --------------------- + --------------------------------------------------- +
| Variable_name | Value |
+ --------------------- + --------------------------------------------------- +
| Slow_query_log | ON |
| Slow_query_log_file |/usr/local/mysql/data/aeolus1-slow_2013-07-19.log |
+ --------------------- + --------------------------------------------------- +
2 rows in set (0.01 sec)

OK. The setting is successful. The idea is like this.

Write a shell script to define the time so that logs can be generated by nature.

Related reading:

MySQL slow query enabling and analysis methods

A good tool for analyzing MySQL slow query logs-mysqlsla

Slow query caused by MySQL prefix Index

[Architecture] MySQL Log File-slow query log

MySQL tuning three steps (slow query and explain profile)

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.