使用percona
1.pt-archiver 功能介绍: 将mysql数据库中表的记录归档到另外一个表或者文件 用法介绍: pt-archiver [OPTION...] --source DSN --where WHERE 这个工具只是归档旧的数据,不会对线上数据的OLTP查询造成太大影响,你可以将数据插入另外一台服务器的其他表中,也可以写入到一个文件中,方便使用load data infile命令导入数据。另外你还可以用它来执行delete操作。这个工具默认的会删除源中的数据。使用的时候请注意。 使用示例: 范例1:将192.168.3.135上的sanmao库的oss_log表id小于100000的记录转移到192.168.3.92上的sanmao库,并归档到oss_log_archive_20120605.log文件中: 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.txtpt-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 differencesVariable localhost.localdomain localhost.localdomain========================= ===================== =====================binlog_cache_size 8388608 2097152have_ndbcluster DISABLED NOinnodb_additional_mem_... 16777216 33554432innodb_buffer_pool_size 1677721600 1073741824 pt-config-diff /etc/my.cnf h=192.168.3.92 --user=root --password=zhang@123 12 config differencesVariable /etc/my.cnf localhost.localdomain========================= =========== =====================binlog_cache_size 8388608 2097152binlog_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 以上就是使用percona-toolkit操作MySQL的实用命令小结_MySQL的内容, |