MySQL slow log query tool-mysqldumpslow

Source: Internet
Author: User
Tags mysql slow query log

When the -- log-slow-queries [= file_name] option is enabled, mysqld writes a log file containing all SQL statements whose execution time exceeds long_query_time seconds. Obtaining the initial lock time is not counted as the execution time.

If the file_name value is not given, no host name is provided by default, and the suffix is-slow. log. If the file name is provided but not the absolute path name, the file is written to the data directory.

After the statement is executed and all locks are released, the slow query log is recorded. The record sequence may be different from the execution sequence.
Slow query logs can be used to locate long-running queries and optimize them. However, it is difficult to check long and slow query logs. To make it easier, you can use the mysqldumpslow command to obtain the query summary displayed in the log to process slow query logs.

In slow query logs of MySQL 5.1, slow queries without indexes are the same as those with indexes. To prevent slow queries that do not use indexes from being recorded in slow query logs, use the -- log-short-format option.

In MySQL 5.1, you can use the -- log-slow-admin-statements server option to write slow management statements, such as optimize table, analyze table, and alter table, into slow query logs.

Queries processed using the query cache are not added to the slow query log. Because the table has zero rows or one row, queries that cannot benefit from the index are not written into the slow query log.
Common Parameters of mysqldumpslow are as follows:

The following parameter after-s indicates the order in which mysqldumpslow results are displayed!
Number of c query executions
T SQL Execution time
L lock table time
R number of rows returned by SQL
Ac, at, al, ar, indicating Reverse Order
-T, Which Is top n, that is, the first n data records are returned.
-G. You can write a regular expression matching later. It is case insensitive.
Display the first two longest executions
[Root @ rac3 python] # mysqldumpslow-s t-t 2/opt/mysql/data/slowquery. log
Reading mysql slow query log from/opt/mysql/data/slowquery. log
Count: 2 Time = 412.54 s (825 s) Lock = 0.00 s (0 s) Rows = 1.0 (2), root [root] @ localhost
Select count (N) from sbtest, t1 where t1.c = sbtest. c
Count: 1 Time = 778.20 s (778 s) Lock = 0.00 s (0 s) Rows = 1.0 (1), root [root] @ localhost
Select count (N) from sbtest where sbtest. id not in (select id from t1)
# The first two most frequently displayed
[Root @ rac3 python] # mysqldumpslow-s c-t 2/opt/mysql/data/slowquery. log
Reading mysql slow query log from/opt/mysql/data/slowquery. log
Count: 12 Time = 0.00 s (0 s) Lock = 0.00 s (0 s) Rows = 1.0 (12), root [root] @ localhost
Select count (N) from tab_1
Count: 2 Time = 412.54 s (825 s) Lock = 0.00 s (0 s) Rows = 1.0 (2), root [root] @ localhost
Select count (N) from sbtest, t1 where t1.c = sbtest. c
[Root @ rac3 python] #

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.