使用percona-toolkit操作MySQL的实用命令小结 |
1.pt-archiver pt-archiver --source h=192.168.3.135,D=sanmao,t=oss_log --user=root --password=zhang@123 --dest h=192.168.3.92,D=sanmao,t=oss_log --file /var/log/oss_log_archive_20120605.log --where "id<=100000" --commit-each 范例2:将192.168.3.135上的sanmao库的oss_log小于160000的记录归档到oss_log_archive_20120607.log文件中: pt-archiver --source h=192.168.3.135,D=sanmao,t=oss_log --user=root --password=zhang@123 --file /var/log/oss_log_archive_20120607.log --where "id<=160000" --commit-each 范例3:删除192.168.3.135上的sanmao库的oss_log表中id小于167050的记录: pt-archiver --source h=192.168.3.135,D=sanmao,t=oss_log --user=root --password=zhang@123 --purge --where id<=167050 注意:如果是字符集是utf8的话,需要在my.cnf中的[client]下面添加default-character-set = utf8,否则导出的文件内容中文会乱码 。 pt-find --ctime +1 --host=192.168.3.135 --engine InnoDB --user=root --password=zhang@123 范例2:查找192.168.3.135中1天以前更改过的数据库名字匹配%hostsops%的并且引擎为MYISAM的表,并将表的引擎更改为InnoDB引擎 。 pt-find --mtime +1 --dblike hostsops --engine MyISAM --host=192.168.3.135 --user=root --password=zhang@123 --exec "ALTER TABLE %D.%N ENGINE=InnoDB" 范例3:查找192.168.3.135中aaa库和zhang库中的空表,并删除 。 pt-find --empty aaa zhang --host=192.168.3.135 --user=root --password=zhang@123 --exec-plus "DROP TABLE %s" 范例4:查找192.168.3.135中超过100M的表: pt-find --tablesize +100M --host=192.168.3.135 --user=root --password=zhang@123 pt-kill --busy-time 60 --print --host=192.168.3.135 --user=root --password=zhang@123 范例2:查找192.168.3.135服务器运行时间超过60s的语句,并kill pt-kill --busy-time 60 --kill --host=192.168.3.135 --user=root --password=zhang@123 范例3:从proccesslist文件中查找执行时间超过60s的语句 mysql -uroot -pzhang@123 -h192.168.3.135 -e "show processlist" > processlist.txt pt-kill --test-matching processlist.txt --busy-time 60 --print 4.pt-config-diff pt-config-diff h=localhost h=192.168.3.92 --user=root --password=zhang@123 比较出来内容如下: 22 config differences Variable localhost.localdomain localhost.localdomain ========================= ===================== ===================== binlog_cache_size 8388608 2097152 have_ndbcluster DISABLED NO innodb_additional_mem_... 16777216 33554432 innodb_buffer_pool_size 1677721600 1073741824 pt-config-diff /etc/my.cnf h=192.168.3.92 --user=root --password=zhang@123 12 config differences Variable /etc/my.cnf localhost.localdomain ========================= =========== ===================== binlog_cache_size 8388608 2097152 binlog_format mixed MIXED pt-config-diff /usr/local/mysql/share/mysql/my-large.cnf /usr/local/mysql/share/mysql/my-medium.cnf
pt-mysql-summary -- --user=root --password=zhang@123 --host=localhost 范例2:汇总本地mysql服务器192.168.3.92的status和配置信息: pt-mysql-summary -- --user=root --password=zhang@123 --host=192.168.3.92 6.pt-variable-advisor pt-variable-advisor --user=root --password=zhang@123 localhost 范例2:从指定的文件中读取配置,这个有格式要求 pt-variable-advisor --user=root --password=zhang@123 --source-of-variables my.cnf |