Percona-Toolkit系列(9) --- pt-find

pt-find

pt-find:官方地址

说明

用途:查找MySQL表并执行指定操作。

语法:

pt-find [OPTIONS] [DATABASES]

pt-find搜索MySQL表并执行操作,如linux中的find命令。默认操作是打印数据库和表名。

具体例子

查看一天前创建的存储引擎是MyISAM的表

[root@BigData ~]# pt-find --host 192.168.20.66 --port 3306 --user root --password 123 --ctime +1 --engine MyISAM
`dbmonitor`.`DB_GROUP`...
`mysql`.`columns_priv`
`mysql`.`db`
`mysql`.`event`
`mysql`.`func`
`mysql`.`help_category`
`mysql`.`help_keyword`
`mysql`.`help_relation`
`mysql`.`help_topic`
`mysql`.`host`
`mysql`.`ndb_binlog_index`
`mysql`.`plugin`
`mysql`.`proc`
`mysql`.`procs_priv`
`mysql`.`proxies_priv`
`mysql`.`servers`
`mysql`.`tables_priv`
`mysql`.`time_zone`
`mysql`.`time_zone_leap_second`
`mysql`.`time_zone_name`
`mysql`.`time_zone_transition`
`mysql`.`time_zone_transition_type`
`mysql`.`user`

查找存储引擎为InnoDB的表并将其转换为存储引擎是MyISAM

[root@BigData ~]# pt-find --host 192.168.20.66 --port 3306 --user root --password 123 --engine InnoDB --exec "ALTER TABLE %D.%N ENGINE=MyISAM"

按照name_sid_pid命名约定,查找由不再存在的进程创建的表,并删除它们

pt-find --host 192.168.20.66 --port 3306 --user root --password 123 --connection-id '\D_\d+_(\d+)$' --server-id '\D_(\d+)_\d+$' --exec-plus "DROP TABLE %s"

查看test和junk数据库中的空表并删除它们

pt-find --host 192.168.20.66 --port 3306 --user root --password 123 --empty junk test --exec-plus "DROP TABLE %s"

查找大小大于5G的表

pt-find --host 192.168.20.66 --port 3306 --user root --password 123 --tablesize +5G

查找行数大于10000的表

pt-find --host 192.168.20.66 --port 3306 --user root --password 123 --rows +10000

查找所有表并打印它们的总数据和索引大小,首先对最大的表进行排序(顺便说一下,排序是另一个程序)

pt-find --host 192.168.20.66 --port 3306 --user root --password 123 --printf "%T\t%D.%N\n" | sort -rn

常用参数:

  • –autoinc=s AUTO_INCREMENT下一个值是n的表
  • –avgrowlen=z 平均行大小为z字节的表
  • –checksum=s checksum为s的表
  • –cmin=z z分钟之前创建的表
  • –collation=s 表排序规则匹配模式
  • –column-name=s 列名与模式匹配的表
  • –column-type=s 表中的一列匹配这种类型(不区分大小写)
  • –comment=s 表注释匹配模式
  • –connection-id=s 表名不存在MySQL连接ID
  • –createopts=s 表创建选项匹配模式
  • –ctime=z n天前创建的表
  • –datafree=z 空闲空间为z字节的表
  • –datasize=z 使用z字节空间大小的表
  • –dblike=s 像SQL语句中LIKE一样匹配数据库名(如:like ‘lei%’)
  • –dbregex=s 正则匹配数据库名
  • –empty 空表
  • –engine=s 存储引擎是s的表
  • –function=s 函数定义匹配模式
  • –indexsize=z 索引占用z字节空间大小的表
  • –kmin=z z分钟前检查过的表
  • –ktime=z z天前检查过的表
  • –mmin=z z分钟前修改过的表
  • –mtime=z z天前修改过的表
  • –procedure=s Procedure definition matches pattern
  • –rowformat=s Table row format matches pattern
  • –rows=z z行数据的表
  • –server-id=s 名称包含server id的表
  • –tablesize=z 使用了z节点大小的表
  • –tbllike=s 像SQL语句中LIKE一样匹配表名(如:like ‘lei%’)
  • –tblregex=s 正则匹配表名
  • –tblversion=z 版本是z的表
  • –trigger=s 某个触发器上的表
  • –trigger-table=s --trigger is defined on table matching pattern
  • –view=s CREATE VIEW matches this pattern
发布了274 篇原创文章 · 获赞 65 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/qianglei6077/article/details/99288944