博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

pt-query-digest工具的功能介绍了:

Posted on 2016-08-08 15:17  moss_tan_jun  阅读(668)  评论(0编辑  收藏  举报

Ok,可以查看 pt-query-digest工具的功能介绍了:
[root@472322 percona-toolkit-2.2.5]# pt-query-digest --help
pt-query-digest analyzes MySQL queries from slow, general, and binary log files.
It can also analyze queries from C<SHOW PROCESSLIST> and MySQL protocol data
from tcpdump.  By default, queries are grouped by fingerprint and reported in
descending order of query time (i.e. the slowest queries first).  If no C<FILES>
are given, the tool reads C<STDIN>.  The optional C<DSN> is used for certain
options like L<"--since"> and L<"--until">.  For more details, please use the
--help option, or try 'perldoc /usr/local/bin/pt-query-digest' for complete
documentation.


Usage: pt-query-digest [OPTIONS] [FILES] [DSN]


Options:


  --ask-pass                  Prompt for a password when connecting to MySQL
  --attribute-aliases=a       List of attribute|alias,etc (default db|Schema)
  --attribute-value-limit=i   A sanity limit for attribute values (default
                              4294967296)
  --charset=s             -A  Default character set
  --config=A                  Read this comma-separated list of config files;
                              if specified, this must be the first option on
                              the command line
  --[no]continue-on-error     Continue parsing even if there is an error (
                              default yes)
  --[no]create-history-table  Create the --history table if it does not exist (
                              default yes)
  --[no]create-review-table   Create the --review table if it does not exist (
                              default yes)
  --daemonize                 Fork to the background and detach from the shell
  --database=s            -D  Connect to this database
  --defaults-file=s       -F  Only read mysql options from the given file
  --embedded-attributes=a     Two Perl regex patterns to capture pseudo-

                              attributes embedded in queries

....................................


分析本地的慢查询文件:

  1. pt-query-digest --user=root --password=m@123 /data/dbdata/localhost-slow.log  



重新回顾满查询日志,并将结果保存到query_review中,注意query_review表的表结构必须先建好,表结构如下:

  1. CREATE TABLE query_review (  
  2.    checksum     BIGINT UNSIGNED NOT NULL PRIMARY KEY,  
  3.    fingerprint  TEXT NOT NULL,  
  4.    sample       TEXT NOT NULL,  
  5.    first_seen   DATETIME,  
  6.    last_seen    DATETIME,  
  7.    reviewed_by  VARCHAR(20),  
  8.    reviewed_on  DATETIME,  
  9.    comments     TEXT  
  10. );  




命令如下:

    1. pt-query-digest --user=root --password=m@123 --review h=localhost,D=test,t=query_review /data/dbdata/localhost-slow.log