


Detailed introduction to MySQL's pt-query-digest analysis of slow query logs
Mar 20, 2017 pm 02:15 PMThis article mainly introduces the relevant information about MySQL slow query pt-query-digest analysis of slow query logs. The introduction in the article is very detailed and has certain reference value for everyone. Friends who need it Let’s take a look together below.
1. Introduction
pt-query-digest is a tool used to analyze mysql slow queries. It Binlog, general log, slowlog can be analyzed, or the MySQL protocol data captured through SHOWPROCESSLIST or tcpdump can be analyzed. The analysis results can be output to a file. The analysis process is to first parameterize the conditions of the query statement, and then perform group statistics on the parameterized queries to calculate the execution time, number, proportion, etc. of each query. You can use the analysis As a result, problems are identified and optimized.
2. Installationpt-query-digest
##2.perl module1 |
|
1 2 3 |
|
1 2 3 4 5 6 |
|
1 |
|
1 |
|
1 |
|
1 |
|
3. pt-query-digest syntax and important options
- ##pt-query-digest [OPTIONS] [FILES] [DSN]
- --create-review-table When using the --review parameter to output the analysis results to a table, it will be automatically created if there is no table.
- --create-history-table When using the --history parameter to output the analysis results to a table, it will be automatically created if there is no table.
- --filter Match and filter the input slow query according to the specified
- string --limit Limits the percentage or quantity of output results. The default value is 20, which means outputting the 20 slowest statements. If it is 50%, it will be sorted from large to small by the total response time, and the output will be cut off when the total reaches 50%.
- --host mysql server address
- --user mysql username
- -- password mysql user password
- --history Save the analysis results to the table. The analysis results are more detailed. The next time you use --history, if the same statement exists and the query is If the time interval is different from that in the history table, it will be recorded in the data table. You can compare the historical changes of a certain type of query by querying the same CHECKSUM.
- --review Save the analysis results to the table. This analysis only parameterizes the query conditions. One type of query is for one record, which is relatively simple. When --review is used next time, if the same statement analysis exists, it will not be recorded in the data table.
- --output analysis result output type, the value can be report (standard analysis report), slowlog (Mysql slow log),
- json --since the time from which to start analysis, the value is a string, which can be a specified time point in the format of "yyyy-mm-dd [hh:mm:ss]" , or it can be a simple time value: s (seconds), h (hours), m (minutes), d (days). For example, 12h means that statistics started 12 hours ago.
- --until deadline, combined with --since can analyze slow queries within a period of time.
4. Analysis of pt-query-digest output results
Part 1: Overall Statistical results
Overall: How many queries are there in total
Time range: The time range of query execution
unique: Unique Number of queries, that is, how many different queries there are after parameterizing the query conditions
total: total min: minimum max: maximum avg: average
95 %: Arrange all values from small to large, the number located at the 95th percentile, this number generally has the most reference value
median: Median, arrange all values from small to large, the position is at The number in the middle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Rank: Ranking of all statements, by default arranged in descending order by query time, passed-- order-by specifies
Query ID: ID of the statement, (remove excess spaces and text characters, calculate
value)
Response: Total Response time
time: The total time proportion of this query in this analysis
calls: Number of executions, that is, how many such queries are there in this analysis Type of query statement
R/Call: Average response time of each execution
V/M: Response time Variance-to-mean ratio
Item:查询对象
1 2 3 4 5 |
|
第三部分:每一种查询的详细统计结果
由下面查询的详细统计结果,最上面的表格列出了执行次数、最大、最小、平均、95%等各项目的统计。
ID:查询的ID号,和上图的Query ID对应
Databases:数据库名
Users:各个用户执行的次数(占比)
Query_time distribution :查询时间分布, 长短体现区间占比,本例中1s-10s之间查询数量是10s以上的两倍。
Tables:查询中涉及到的表
Explain:SQL语句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
五、用法示例
1.直接分析慢查询文件:
1 |
|
2.分析最近12小时内的查询:
1 |
|
3.分析指定时间范围内的查询:
1 |
|
4.分析指含有select语句的慢查询
1 |
|
5.针对某个用户的慢查询
1 |
|
6.查询所有所有的全表扫描或full join的慢查询
1 |
|
7.把查询保存到query_review表
1 |
|
8.把查询保存到query_history表
1 2 |
|
9.通过tcpdump抓取mysql的tcp协议数据,然后再分析
1 2 |
|
10.分析binlog
1 2 |
|
11.分析general log
1 |
|
总结
The above is the detailed content of Detailed introduction to MySQL's pt-query-digest analysis of slow query logs. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP's big data structure processing skills

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP?

What are the application scenarios of Java enumeration types in databases?

How to insert data into a MySQL table using PHP?

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP?

Performance optimization strategies for PHP array paging
