MySQL slow_query_log

Source: Internet
Author: User

Slow_query_log is a parameter that records SQL execution for more than a certain period of time.

Slow query log related variables

1. Command line parameters:

-- Log-slow-queries

Specifies the location where the log file is stored, which can be null, and the system gives a default file host_name-slow.log

2. System variables

Log_slow_queries

Specifies the location where the log file is stored, which can be null, and the system gives a default file host_name-slow.log

Slow_query_log

The slow quere log switch. If the value is 1, the slow query is enabled.

Slow_query_log_file

Specifies the location where the log file is stored, which can be null, and the system gives a default file host_name-slow.log

Long_query_time

The time when the record expires. The default value is 10 s.

Log_queries_not_using_indexes

You can choose whether to enable the query that does not use the index after logs.

It is a very useful parameter for discovering SQL statements that take too long to effectively improve database performance.

This section describes how to configure MySQL 5.1 or later.

Modify/etc/my. cnf

Slow_query_log: valid (0 or OFF), invalid (1 or ON)
Slow_query_log_file: specify the log file
Long_query_time: the SQL statement that exceeds the specified time will be recorded in the log file (the default time is 10 seconds)
※Mysql5.1 can be set to less than 1 second.

# Vi/etc/my. cnf
[Mysqld]
...
Slow_query_log = 1
Slow_query_log_file =/data/log/mysql/slow_query.log
Long_query_time = 5

Use set global

# Mysql-u <user name>-p <database name>
Enter password: [Enter the password]

Set global slow_query_log = 1;
Set global slow_query_log_file = '/data/log/mysql/slow_query.log ';
Set global long_query_time = 5;

Configuration efficiency

After you restart MySQL or set global, the configuration will be valid.

Summary

The slow response of the database causes the slow response of the entire system. We recommend that you install MySQL to make slow_query_log effective.

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.