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