Mysql-view slow SQL statements

Source: Internet
Author: User

Check whether MySQL has enabled viewing slow SQL log files

(1) Check whether slow SQL logs are enabled

Mysql> show variables like 'Log _ slow_queries ';

+ ------------------ + ------- +

| Variable_name | value |

+ ------------------ + ------- +

| Log_slow_queries | on |

+ ------------------ + ------- +

1 row in SET (0.00 Sec)


(2) Check the seconds in which the SQL statement will be executed and recorded in the log file.
Mysql> show variables like 'long _ query_time ';

+ ----------------- + ------- +

| Variable_name | value |

+ ----------------- + ------- +

| Long_query_time | 1 |

+ ----------------- + ------- +

1 row in SET (0.00 Sec)

Here value = 1, indicating 1 second

 

2. configure My. INI file (the file name in inux is my. CNF), find the [mysqld] section, and add the log configuration, as shown in the following example:

[mysqld]

log =" C:/temp/MySQL. log "

log_slow _ Queries = "C:/temp/mysql_slow.log"

long_query_time = 1


log indicates the log file storage directory.

log_slow_queries indicates the SQL log directory with a long execution time;

long_query_time indicates the execution time, in seconds.


in Linux, these configuration items should already exist, but have been commented out. You can remove the annotations. However, it is okay to add configuration items directly.

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.