percona-toolkit学习笔记(七)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介:

pt-fifo-split

功能:

    模拟切割文件并通过管道传递给先入先出队列而不用真正的切割文件

 

说明:

    pt-fifo-split读取大文件中的数据并打印到fifo文件,每次达到指定行数就往fifo文件中打印一个EOF字符,读取完成以后,关闭掉fifo文件并移走,然后重建fifo文件,打印更多的行。这样可以保证你每次读取的时候都能读取到制定的行数直到读取完成。注意此工具只能工作在类unix操作系统。这个程序对大文件的数据导入数据库非常有用,具体参考:https://www.percona.com/blog/2008/07/03/how-to-load-large-files-safely-into-innodb-with-load-data-infile/

 

实例:

    一次读取100行记录

    pt-fifo-split--lines 100 /root/all.sql

    while[ -e /tmp/pt-fifo-split ]; do cat /tmp/pt-fifo-split; done

 

pt-find

功能:Find MySQL tables and executeactions, like GNU find

 

说明:

    pt-findsearches for MySQL tables and executes actions, like GNU find.  The default action is to print the databaseand table name.

 

实例:

pt-find --ctime -1 --engine MyISAM-uroot -proot -h localhost  # 列出创建时间小于1天且使用MyISAM引擎的数据表

pt-find --engine InnoDB -uroot-proot -h localhost              # 列出InnoDB引擎的表

pt-find --ctime -1 -uroot -proot-h localhost --exec-plus "drop table %s"  # 将找到的符合条件的table删除掉

pt-find --tablesize +500M -uroot-proot -h localhost               # 列出总大小超过500M的表

pt-find hellodb -uroot -proot -hlocalhost       # 列出hellodb库里的所有表

pt-find --printf"%T\t%D.%N\n"  -uroot -proot -hlocalhost | sort -rn # 列出所有表的total data and index size,并从大到小排序


pt-fingerprint

功能:Convert queries into fingerprints.

       用于生成查询指纹。主要将将sql查询生成queryIDpt-query-digest中的ID即是通过此工具来完成的。
       类似于Oracle中的SQL_ID,涉及绑定变量,字面量等

 

说明:

    pt-findsearches for MySQL tables and executes actions, like GNU find.  The default action is to print the databaseand table name.

 

实例:

    #pt-fingerprint --query "select a,b,c from hellodb.students wherestuid=22"

 

pt-ioprofile

功能:pt-ioprofile的原理是对某个pid附加一个strace进程进行IO分析

    pt-ioprofileuses "strace" and "lsof" to watch a process’s IO and printout a table of files and I/O activity. By default, it watches the mysqld process for 30 seconds.

 

pt-kill

功能:Kill掉符合指定条件mysql语句

 

官方示例:

Kill queries runninglonger than 60s:

# pt-kill --busy-time 60 --kill

 

Print, do not kill,queries running longer than 60s:

# pt-kill --busy-time 60 --print

 

Check for sleepingprocesses and kill them all every 10s:

# pt-kill --match-command Sleep--kill --victims all --interval 10

 

Print all loginprocesses:

# pt-kill --match-state login--print --victims all

 

See which queries inthe processlist right now would match:

# mysql -e "SHOWPROCESSLIST" > proclist.txt

# pt-kill --test-matchingproclist.txt --busy-time 60 --print

 

pt-stalk

功能:用于收集mysql数据库故障时的相关信息便于后续诊断处理。Collect forensic data about MySQLwhen problems occur

 

pt-stalk等待触发条件触发,然后收集数据帮助错误诊断,它被设计成使用root权限运行的守护进程,因此你可以诊断那些你不能直接观察的间歇性问题。默认的诊断触发条件为SHOW GLOBAL STATUS。也可以指定processlist为诊断触发条件,使用--function参数指定。

 

 

范例1:指定诊断触发条件为status,同时运行语句超过20的时候触发,收集的数据存放在/tmp/test目录下:

# pt-stalk  --function status \

--variable Threads_running--threshold 20 \

--dest /tmp/test -- -uroot -proot -h192.168.2.11

 

范例2:指定诊断触发条件为processlist,超过20个状态为statistics触发,收集的数据存放在/tmp/test目录下:

# pt-stalk  --function processlist \

--variable State --matchstatistics --threshold 20 \

--dest /tmp/test -- -uroot -proot -h192.168.2.11

 










本文转自 lirulei90 51CTO博客,原文链接:http://blog.51cto.com/lee90/1772205,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
监控 关系型数据库 MySQL
MySQL percona-toolkit工具包的安装和使用(超详细版)
转载:https://www.cnblogs.com/zishengY/p/6852280.html 一.检查和安装与Perl相关的模块     PT工具是使用Perl语言编写和执行的,所以需要系统中有Perl环境。
1980 0
|
Java 关系型数据库 MySQL
|
关系型数据库 MySQL Unix
MySQL中的Percona-toolkit工具由来漫谈
首先问一个问题,你听说过下面这两个工具吗? Maatkit 和Aspersa 如果听过,可能就暴露年龄了,你如果现在去查Aspersa相关的文章,会发现下载链接之类的都不可用了。
1683 0
|
监控 关系型数据库 MySQL
|
Perl
percona-toolkit-3.0.4安装
percona-toolkit
1463 0
|
监控 MySQL 关系型数据库
|
关系型数据库 数据库 索引
|
监控 关系型数据库 MySQL
|
SQL 关系型数据库 MySQL