MySQL Slow query log learning

Source: Internet
Author: User
Tags time 0 install perl mysql slow query log

Mysqlsla is a MySQL log analysis tool launched by hackmysql.com, which is very powerful. Data reports are very useful for analyzing the causes of slow queries, including frequency of execution, amount of data, query consumption, etc.

First, use

1 # mysqlsla -lt slow mysql-slow.log

Or

1 # mysqlsla -lt slow mysql-slow.log -sf “+SELECT” -db dbName -top 10 -sort t_sum

Parameter description:
LT: Indicates the log type, with slow, general, binary, MSL, UDL.
Sf:[+-][type],[type] has SELECT, CREATE, DROP, UPDATE, INSERT, such as "+select,insert", does not appear by default--that is, not included.
DB: The log of which library to process.
Top: Indicates how many first bars are sorted by rule.
Sort: Sorted by some rule, t_sum sorted by total time, c_sum by total number of times.

Ii. Analysis Results
Total queries (queries totals), number of SQL to go back (unique)
Sorting the contents of the output report (sorted by)
The most significant slow SQL statistics, including the average execution time, the waiting lock time, the total number of result rows, and the total number of rows scanned.
Count, the number of executions of SQL and the percentage of total slow log count.
Time, execution times, including total time, average time, minimum, maximum time, and percentage of total slow SQL time.
95% of time, removing the fastest and slowest SQL, coverage accounted for 95% of SQL execution times.
Lock time, waiting for the lock.
95% of lock, 95% slow SQL waits for lock time.
Rows sent, resulting row statistics, including average, minimum, maximum number.
Rows examined, the number of lines scanned.
database, which databases belong to
Users, which user, IP, accounts for the percentage of SQL performed by all users
Query abstract, SQL statement after abstraction
Query sample, SQL statement

Third, installation

1 # wget http://hackmysql.com/scripts/mysqlsla-2.03.tar.gz
2 # tar zxvf mysqlsla-2.03.tar.gz
3 # cp mysqlsla-2.03/bin/mysqlsla /usr/local/bin

If you are prompted with "Can ' t locate dbi.pm", execute the following command

1 # yum install perl-DBI perl-DBD-MySQL -y
2 # mysqlsla -lt slow slow.log

Iv. examples

1 # mysqlsla /tmp/mysqlslow.log | less

auto-detected logs as slow logs
Report for slow logs:/tmp/mysqlslow.log
6 queries total, 6 unique
Sorted by ' T_sum '
Grand Totals:time 0 S, Lock 0 s, rows sent, rows examined 13
______________________________________________________________________ 001 ___
Count:1 (16.67%)
time:2.321 Ms Total, 2.321 MS Avg, 2.321 ms to 2.321 Ms Max (47.2%)
Lock time (s): 629? s total, 629 's AVG, 629? s to 629? s Max (77.75%)
Rows Sent:8 AVG, 8 to 8 Max (61.54%)
Rows Examined:8 AVG, 8 to 8 Max (61.54%)
Database:
Users:
[Email protected] 192.168.1.100:100.00% (1) of query, 100.00% (6) of all users

Query Abstract:
SET timestamp=n; SHOW variables like ' S ';

Query Sample:
SET timestamp=1252395365;
Show variables like '%character% ';
......
The format description is as follows:
Total queries (queries totals), number of SQL to go back (unique)
Sorting the contents of the output report (sorted by)
The most significant slow SQL statistics, including the average execution time, the waiting lock time, the total number of result rows, and the total number of rows scanned.

Count, the number of executions of SQL and the percentage of total slow log count.
Time, execution times, including total time, average time, minimum, maximum time, and percentage of total slow SQL time.
95% of time, removing the fastest and slowest SQL, coverage accounted for 95% of SQL execution times.
Lock time, waiting for the lock.
95% of lock, 95% slow SQL waits for lock time.
Rows sent, resulting row statistics, including average, minimum, maximum number.
Rows examined, the number of lines scanned.
database, which databases belong to
Users, which user, IP, accounts for the percentage of SQL performed by all users

Query abstract, SQL statement after abstraction
Query sample, SQL statement

In addition to the above output, the official also provides a lot of custom parameters, is a rare good tool.


MySQL Slow query log learning

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.