MySQL Slow query log configuration method detailed

Source: Internet
Author: User
Tags mysql slow query log

To see if the MySQL server's slow query status is turned on:

1 show variables like'%slow%';

    • Slow_launch_time, which means more than 2 seconds is defined as a slow query
    • Log_slow_queries and Slow_query_log, indicating that the slow query has been opened
    • Slow_query_log_file, the location of the file that represents the slow query log

In the MySQL configuration file my.cnf or my.ini [mysqld] Add the slow query configuration statement settings to open the slow query state :

1 #定义超过指定时间(秒)的查询,可用小数
2 long_query_time = 2
3 #定义慢查询日志路径(此目录文件一定要有写权限)
4 log-slow-queries=C:/slowquery.log
5 #未使用索引的查询也被记录到慢查询日志中
6 log-queries-not-using-indexes

Once configured, restart MySQL, the MySQL server's slow query status has been opened:

Of course, you can also use the SET command to set the state of a MySQL variable, but this setting is temporary:

1 setglobalslow_query_log=on; #开启
2 setglobalslow_query_log=off; #关闭

Precautions:


Slow query time should not be set too long, otherwise not very meaningful

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.