MySQL slow query Configuration

Source: Internet
Author: User
Tags dedicated server
Slow query logs are composed of some SQL statements. When the query time exceeds the value of long_query_time, the slow query log is generated. The minimum value of longquerytime is 1 s and the default value is 1 s.

Slow query logs are composed of some SQL statements. When the query time exceeds the value of long_query_time, the slow query log is generated. The minimum value of longquerytime is 1 s and the default value is 1 s.

Slow query logs are composed of some SQL statements. When the query time exceeds the value of long_query_time, the slow query log is generated. The minimum value of longquerytime is 1 s and the default value is 10 s.

Check whether MySQL slow query is Enabled:

Mysql> show variables like '% slow % '; + --------------------- + bytes + | Variable_name | Value | + --------------------- + bytes + | slow_launch_time | 2 | slow_query_log | OFF | slow_query_log_file | E: \ Program Files \ mysql-5.6.10-winx64 \ data \ lzjun-slow.log | + --------------------- + -------------------------------------------------------- + 3 rows in set (0.00 sec)

By default, the slowquerylog of MySQL is OFF. The following methods are enabled:

  • When MySQL is started:

    Mysqld -- slow_query_log = [{0 | 1}] # MySQL5.5 or a later version

    If you do not specify a value or 1, 0 indicates that mysqld -- slowquerylogfile = filename indicates where the log file is saved. If you specify a value, it is saved in the homename-slow.log file that stores the data directory by default.

    Mysqld -- log-slow-queries [= file_name] # MySQL5.1 and earlier versions
  • Set MySQL after startup

    Set global slow_query_log = [1 | 0 | ON | OFF] set global slow_query_log_file = [file_name]
  • Configuration in my. ini

    Slow_query_log = 1slow_query_log_file =/var/log/mysql_slow.log
  • Generally, the value of longquerytime should not be too large. The default value is 10 seconds, which is usually 2-5 seconds. Of course, slow query logs may affect MySQL performance. For the master-slave structure, open a dedicated server to monitor slow queries.

    This article permanently updates the link address:

    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.