广告
返回顶部
首页 > 资讯 > 数据库 >Mysql pt工具pt-kill怎么用
  • 444
分享到

Mysql pt工具pt-kill怎么用

2024-04-02 19:04:59 444人浏览 泡泡鱼
摘要

Mysql pt工具pt-kill怎么用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。 pt-kill 概述 从show

Mysql pt工具pt-kill怎么用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

pt-kill

概述

从show processlist 中获取满足条件的连接或者从包含show processlist的文件中读取满足条件的连接并打印或者杀掉或者执行其他操作,这个工具在工作中实用性很高,当服务器连接出现异常后第一想到的就是pt-kill,自己写一个脚本也可以,但是功能还是没有pt-kill强大;

常用功能介绍


  1. [root@hostnfsd :/root]$ pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --busy-time 60 --kill --victims all --interval 10           每隔10s 杀掉处于runnning状态超过60s的连接数;

  2. [root@hostnfsd :/root]$ pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --match-command Sleep --kill --victims all --interval 10    每隔10s 杀掉处于sleep状态的连接数;

  3. [root@hostnfsd :/root]$ pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --idle-time 60 --kill --victims all --interval 10           每隔10s 杀掉已经sleep达到60秒的连接数;

匹配状态stat处于sendind data的
[root@HaoDai_App_DB01 toolsqldir]# pt-kill --defaults-file=/data/mydata/my_3307.cnf -uroot -p`cat /etc/sqlpass` --match-state Sending --kill --victims all --interval 5

  1. 参数

  2. –busy-time

  3. 运行时间

  4. –idle-time

  5. 空闲时间

  6. –victims

  7. 所有匹配的连接,对应有最久的连接

  8. –interval

  9. 间隔时间,默认30s,有点长,可以根据实际情况来调节

  10. –print

  11. 打印出来kill掉的连接


  12. –match-command

  13. 匹配当前连接的命令


  14. Query

  15. Sleep

  16. Binlog Dump

  17. Connect

  18. Delayed insert

  19. Execute

  20. Fetch

  21. Init DB

  22. Kill

  23. Prepare

  24. Processlist

  25. Quit

  26. Reset stmt

  27. Table Dump

  1. –match-state

  1. 匹配当前连接的状态

  1. Locked

  2. login

  3. copy to tmp table

  4. Copying to tmp table

  5. Copying to tmp table on disk

  6. Creating tmp table

  7. executing

  8. Reading from net

  9. Sending data

  10. Sorting for order

  11. Sorting result

  12. Table lock

  13. Updating

  14. –match-info

  15. 使用正则表达式匹配符合的sql

  16. –match-db –match-user –match-host

  17. 见名知意

  18. 常用用法

  19. 杀掉空闲链接

  20. pt-kill –match-command Sleep –idle-time 5 –host –port –interval –print –kill –victims all

  21. 杀掉运行时间超过5s的链接

  22. pt-kill –match-command Query –busy-time 5 –host –port –interval –print –kill –victims all

  23. 杀掉匹配某个规则的正在运行的sql

  24. pt-kill –match-command Query –busy-time 5 –host –port –interval –print –kill –victims all –match-info

  25. 杀掉正在进行filesort的sql

  26. pt-kill –match-command Query –match-state “Sorting result” busy-time 5 –host –port –interval –print –kill –victims all

  27. 杀掉正在Copying to tmp table的sql

  28. pt-kill –match-command Query –match-state “Copying to tmp table” busy-time 5 –host –port –interval –print –kill –victims all

几个重要参数

--daemonize  放在后台以守护进程的形式运行;
--interval  多久运行一次,单位可以是s,m,h,d等默认是s
--victims 默认是oldest,只杀最古老的查询。这是防止被查杀是不是真的长时间运行的查询,他们只是长期等待。这种种匹配按时间查询,杀死一个时间最高值。 all 杀掉所有满足的线程 杀死所有,但最长的保留不杀 action
--kill                 杀掉连接并且退出
--kill-query           只杀掉连接执行的语句,但是线程不会被终止
--print                打印满足条件的语句
	QUERY MATCHES--busy-time 批次查询已运行的时间超过这个时间的线程; --idle-time 杀掉sleep 了多少时间的连接线程,必须在--match-command sleep时才有效opition查看参数吧 
		Usage: pt-kill [OPTIONS] [DSN]


Options:


  --ask-pass             Prompt for a passWord when connecting to mysql
  --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
  --create-log-table     Create the --log-dsn table if it does not exist
  --daemonize            Fork to the background and detach from the shell
  --database=s       -D  The database to use for the connection
  --defaults-file=s  -F  Only read mysql options from the given file
  --filter=s             Discard events for which this Perl code doesn't return
                         true
  --group-by=s           Apply matches to each class of queries grouped by this
                         SHOW PROCESSLIST column
  --help                 Show help and exit
  --host=s           -h  Connect to host (default localhost)
  --interval=m           How often to check for queries to kill.  Optional
                         suffix s=seconds, m=minutes, h=hours, d=days; if no
                         suffix, s is used.
  --log=s                Print all output to this file when daemonized
  --log-dsn=d            Store each query killed in this DSN
  --password=s       -p  Password to use when connecting
  --pid=s                Create the given PID file
  --port=i           -P  Port number to use for connection
  --query-id             Prints an ID of the query that was just killed
  --rds                  Denotes the instance in question is on Amazon RDS
  --run-time=m           How long to run before exiting.  Optional suffix s=
                         seconds, m=minutes, h=hours, d=days; if no suffix, s
                         is used.
  --sentinel=s           Exit if this file exists (default /tmp/pt-kill-
                         sentinel)
  --set-vars=A           Set the MySQL variables in this comma-separated list
                         of variable=value pairs
  --Socket=s         -S  Socket file to use for connection
  --stop                 Stop running instances by creating the --sentinel file
  --[no]strip-comments   Remove SQL comments from queries in the Info column of
                         the PROCESSLIST (default yes)
  --user=s           -u  User for login if not current user
  --verbose          -v  Print infORMation to STDOUT about what is being done
  --version              Show version and exit
  --[no]version-check    Check for the latest version of Percona Toolkit,
                         MySQL, and other programs (default yes)
  --victims=s            Which of the matching queries in each class will be
                         killed (default oldest)
  --wait-after-kill=m    Wait after killing a query, before looking for more to
                         kill.  Optional suffix s=seconds, m=minutes, h=hours,
                         d=days; if no suffix, s is used.
  --wait-before-kill=m   Wait before killing a query.  Optional suffix s=
                         seconds, m=minutes, h=hours, d=days; if no suffix, s
                         is used.


Actions:


  --execute-command=s    Execute this command when a query matches
  --kill                 Kill the connection for matching queries
  --kill-query           Kill matching queries
  --print                Print a KILL statement for matching queries; does not
                         actually kill queries


Class Matches:


  --any-busy-time=m      Match query class if any query has been running for
                         longer than this time. "Longer than" means that if you
                         specify 10, for example, the class will only match if
                         there's at least one query that has been running for
                         greater than 10 seconds.  Optional suffix s=seconds, m=
                         minutes, h=hours, d=days; if no suffix, s is used.
  --each-busy-time=m     Match query class if each query has been running for
                         longer than this time. "Longer than" means that if you
                         specify 10, for example, the class will only match if
                         each and every query has been running for greater than
                         10 seconds.  Optional suffix s=seconds, m=minutes, h=
                         hours, d=days; if no suffix, s is used.
  --query-count=i        Match query class if it has at least this many queries


Query Matches:


  --busy-time=m          Match queries that have been running for longer than
                         this time.  Optional suffix s=seconds, m=minutes, h=
                         hours, d=days; if no suffix, s is used.
  --idle-time=m          Match queries that have been idle/sleeping for longer
                         than this time.  Optional suffix s=seconds, m=minutes,
                         h=hours, d=days; if no suffix, s is used.
  --ignore-command=s     Ignore queries whose Command matches this Perl regex
  --ignore-db=s          Ignore queries whose db (database) matches this Perl
                         regex
  --ignore-host=s        Ignore queries whose Host matches this Perl regex
  --ignore-info=s        Ignore queries whose Info (query) matches this Perl
                         regex
  --[no]ignore-self      Don't kill pt-kill's own connection (default yes)
  --ignore-state=s       Ignore queries whose State matches this Perl regex (
                         default Locked)
  --ignore-user=s        Ignore queries whose user matches this Perl regex
  --match-all            Match all queries that are not ignored
  --match-command=s      Match only queries whose Command matches this Perl
                         regex
  --match-db=s           Match only queries whose db (database) matches this
                         Perl regex
  --match-host=s         Match only queries whose Host matches this Perl regex
  --match-info=s         Match only queries whose Info (query) matches this
                         Perl regex
  --match-state=s        Match only queries whose State matches this Perl regex
  --match-user=s         Match only queries whose User matches this Perl regex
  --replication-threads  Allow matching and killing replication threads
  --test-matching=a      Files with processlist snapshots to test matching
                         options against  		

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注编程网数据库频道,感谢您对编程网的支持。

您可能感兴趣的文档:

--结束END--

本文标题: Mysql pt工具pt-kill怎么用

本文链接: https://www.lsjlt.com/news/62099.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Mysql pt工具pt-kill怎么用
    Mysql pt工具pt-kill怎么用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。 pt-kill 概述 从show...
    99+
    2022-10-18
  • mysql中pt-osc工具怎么用
    这篇文章将为大家详细讲解有关mysql中pt-osc工具怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 使用方法:pt-online-...
    99+
    2022-10-18
  • MySQL中pt-duplicate-key-checker工具怎么用
    这篇文章主要为大家展示了“MySQL中pt-duplicate-key-checker工具怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“MySQL中pt-...
    99+
    2022-10-18
  • MySQL中pt-query-digest工具怎么使用
    这篇文章主要介绍“实例分析MySQL中pt-query-digest工具的使用记录”,在日常操作中,相信很多人在实例分析MySQL中pt-query-digest工具的使用记录问题上存在疑惑,小编查阅了各式...
    99+
    2022-12-07
    mysql pt-query-digest
  • MySQL online ddl工具之pt-online-schema-change怎么用
    这篇文章主要介绍MySQL online ddl工具之pt-online-schema-change怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!MySQL ddl 的问题现状...
    99+
    2022-10-18
  • pt-table-checksum工具应用
        1.认真看错误提示,弄不清楚状况的时候打开debugPTDEBUG=1     2.10.10.10.10为主,其它ip为从  ...
    99+
    2022-10-18
  • MySQL如何使用pt-kill杀除大SQL
    这篇文章给大家分享的是有关MySQL如何使用pt-kill杀除大SQL的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。 下载地址https://www...
    99+
    2022-10-18
  • MySQL慢日志分析工具pt-query-digest怎么用
    小编给大家分享一下MySQL慢日志分析工具pt-query-digest怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!一、...
    99+
    2022-10-18
  • MySQL pt-slave-restart工具的使用简介
        在MySQL主从复制环境的搭建中,常常会遇到一种场景,主库和从库都要初始化用户的账号密码,正常的情况下,需要在主库和从库都关闭session级别的binlog,然后再进行用户信息导入。 &...
    99+
    2022-05-18
    MySQL pt-slave-restart pt-slave-restart工具的使用
  • mysql慢查询分析工具之PT
    1. 工具简介pt-query-digest是用于分析mysql慢查询的一个工具,它可以分析binlog、General log、slowlog,也可以通过SHOWPROCESSLIST或者通过tcpdu...
    99+
    2022-10-18
  • mysql中如何使用percona的pt-archiver工具
    这篇文章给大家分享的是有关mysql中如何使用percona的pt-archiver工具的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。DBA或者运维人员经常需定期对数据进行归档和...
    99+
    2022-10-18
  • 如何使用pt-query-digest工具
    这篇文章将为大家详细讲解有关如何使用pt-query-digest工具,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 slow log 分析...
    99+
    2022-10-18
  • Percona-Toolkit中pt-kill用法是怎样的呢
    Percona-Toolkit中pt-kill用法是怎样的呢,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。生产环境中我们时常遇...
    99+
    2022-10-18
  • pt-query-digest慢查询分析工具怎么用
    这篇文章主要介绍了pt-query-digest慢查询分析工具怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。 ...
    99+
    2022-10-18
  • pt-table-checksum,?pt-table-sync及percona-toolkit工具包的安装和使用
    percona-toolkit MySQL的一个很有用的工具 详情请参考 http://www.cnblogs.com/zping/p/5678652.html 检查数据一致性(前提是 从库必须是活动的)...
    99+
    2022-10-18
  • 如何使用pt工具检测MySQL主从延迟
    小编给大家分享一下如何使用pt工具检测MySQL主从延迟,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!   ...
    99+
    2022-10-18
  • MySQL慢查询分析工具pt-query-digest详解
    目录一、简介二、安装pt-query-digest三、pt-query-digest语法及重要选项四、分析pt-query-digest输出结果五、用法示例一、简介 pt-query-digest是用于分析mysql慢查...
    99+
    2023-01-13
    MySQL慢查询分析工具 MySQL慢查询 MySQL慢查询pt-query-diges
  • MySQL中pt-show-grants怎么用
    这篇文章主要介绍了MySQL中pt-show-grants怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。 ...
    99+
    2022-10-18
  • MySQL修改大表工具pt-online-schema-change的原理
    这篇文章主要讲解了“MySQL修改大表工具pt-online-schema-change的原理”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MySQL修改大...
    99+
    2022-10-18
  • mysql中pt-online-schema-change怎么用
    这篇文章主要介绍了mysql中pt-online-schema-change怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。pt-onl...
    99+
    2022-10-18
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作