mysql-turn on slow query & all operations logging

Source: Internet
Author: User
Tags mysql version

In the process of operating the website, you may encounter the problem of a sudden slow web site, in general, and MySQL slow relationship, you can open the slow query , to find the efficiency of SQL , and then take appropriate measures. Here's how to turn on slow queries:

1. Turn on slow query

Locate the MySQL configuration file, my.cnf (Windows My.ini), and add the following lines under [Mysqld]:

long_query_time=2
log-slow-queries=/usr/var/slowquery.log


The above 2 is the time of the query, that is, when a SQL execution time exceeds 2 seconds to record ,/usr/var/slowquery.log is the location of the log records.

Then restart the MySQL service

Note that the MySQL 5.6 version, logging slow query log configuration has been modified to:

long_query_time=2
Slow_query_log=1
Slow_query_log_file=/tmp/slow-query.log

Additionally, a configurable record does not use the indexed query log:
Log_queries_not_using_indexes=1

2. Location of MySQL configuration files

The windows:windows configuration file is My.ini, usually under the MySQL installation directory or under C:\Windows.

Linux: Linux configuration file is my.cnf, usually in/etc.

Note: The current MySQL connection process can be viewed by mysql>show full processlist;

3. To record all operation logs, including select

Added in My.ini or my.cnf profile, [mysqld]: log= file name

Example: Log=/tmp/mysqlquery.log

Restart Mysqld, which will record all relevant operational logs

Note: Log record location, MySQL should have write permission;

Note that in MySQL version 5.6, the configuration of all operation logs is changed to:

General_log=on
General_log_file=/tmp/mysqlquery.log

mysql-turn on slow query & all operations logging

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.