标签:pt-duplicate-key-checker pt-find pt-fk-error-logger pt-toolkit
pt-duplicate-key-checker
功能为从mysql表中找出重复的索引和外键,这个工具会将重复的索引和外键都列出来,并生成了删除重复索引的语句,非常方便 找出多余的索引: pt-duplicate-key-checker --user=root --password=db123 --socket=/var/tmp/mysql.sock --database=game 结果: # ######################################################################## # game.tb_xxx # ######################################################################## # IDX_TB_CORE_URL_REWRITE_ID_PATH is a left-prefix of UNQ_TB_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID # Key definitions: # KEY `IDX_TB_CORE_URL_REWRITE_ID_PATH` (`id_path`), # UNIQUE KEY `UNQ_TB_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID` (`id_path`,`is_system`,`store_id`), # Column types: # `id_path` varchar(255) default null comment ‘id path‘ # `is_system` smallint(5) unsigned default ‘1‘ comment ‘defines is rewrite system‘ # `store_id` smallint(5) unsigned not null default ‘0‘ comment ‘store id‘ # To remove this duplicate index, execute: ALTER TABLE `game`.`tb_xxx` DROP INDEX `IDX_TB_CORE_URL_REWRITE_ID_PATH`; # ######################################################################## # Summary of indexes # ######################################################################## # Size Duplicate Indexes 768 # Total Duplicate Indexes 1 # Total Indexes 157
pt-fingerprint
功能 额,不知道有什么用。
例子:pt-fingerprint --query "select a, b, c from users where id = 500 and create_time between ‘2015-01-01‘ and 2015-02-02‘“ 结果:select a, b, c from users where id = ? and create_time between ? and ?‘
pt-fk-error-logger
Usage pt-fk-error-logger [OPTION...] SOURCE_DSN pt-fk-error-logger extracts and saves information about the most recent foreign key errors in a MySQL server. 打印外键错误 pt-fk-error-logger -uroot -p123456 h=127.0.0.1 把外键错误保存到表里,需要先创建表,建议表的结构如下: pt-fk-error-logger -uroot -p123456 h=127.0.0.1 --dest h=127.0.0.1,D=db,t=foreign_key_errors CREATE TABLE foreign_key_errors ( ts datetime NOT NULL, error text NOT NULL, PRIMARY KEY (ts) )
pt-fifo-split
功能分割文件,将大文件按条件分割成小文件
例子:
pt-fifo-split --lines 1000000 hugefile.txt while [ -e /tmp/pt-fifo-split ]; do cat /tmp/pt-fifo-split; done 按一下例子能会比较快速的导入数据。 pt-fifo-split infile.txt --fifo /tmp/my-fifo --lines 1000000 while [ -e /tmp/my-fifo ]; do mysql -e "set foreign_key_checks=0; set sql_log_bin=0; set unique_checks=0; load data local infile ‘/tmp/my-fifo‘ into table load_test fields terminated by ‘\t‘ lines terminated by ‘\n‘ (col1, col2);" sleep 1; done
Pt-find
pt-find [OPTION...] [DATABASE...] pt-find 查找mysql表并执行指定的命令,和gnu的find命令类似
查找本机中一天以前创建的Innodb表 pt-find --user=root --password=123456 -h127.0.0.1 --ctime +1 --engine Innodb 查找 Myisam 表 并 转成 innnodb: pt-find --user=root --password=123456 -h127.0.0.1 --engine MyISAM --exec "ALTER TABLE %D.%N ENGINE=Innodb" Find tables created by a process that no longer exists, following the name_sid_pid naming convention, and remove them. pt-find -uroot -p123456 -h127.0.0.1 --connection-id ‘\D_\d+_(\d+)$‘ --server-id ‘\D_(\d+)_\d+$‘ --exec-plus "DROP TABLE %s" 查找junk和test中的空表,并删除 pt-find -uroot -p123456 -h127.0.0.1 --empty junk test --exec-plus "DROP TABLE %s" 查找库中大小超过5G的表 pt-find --tablesize +5G 找出所有的表和索引大小并打印排序 pt-find --user=root --password=123456 -h127.0.0.1 --printf "%T\t%D.%N\n" | sort -rn 如上所述,但是这一次,其后插入数据到数据库中 pt-find --noquote --exec "INSERT INTO sysdata.tblsize(db, tbl, size) VALUES(‘%D‘, ‘%N‘, %T)"
本文出自 “孜孜不倦的学习着...” 博客,请务必保留此出处http://jonyisme.blog.51cto.com/3690784/1758959
Percona Toolkit 学习(三)(pt-duplicate-key-checker,)
标签:pt-duplicate-key-checker pt-find pt-fk-error-logger pt-toolkit
原文地址:http://jonyisme.blog.51cto.com/3690784/1758959