您的位置:首页 > 其它

Percona-tookit学习笔记(二)

2016-05-11 13:52 429 查看
pt-align作用:对其他pt工具生成的结果做格式化输出
例如:pt-mysql-summary --user=root--password=root -h localhost|pt-align 【pt-mysql-summary这个工具后面会讲到,这里为了演示pt-align的作用】
命令的执行结果如下:




pt-archiver
作用:Archive rows from a MySQL table into anothertable or a file.
示例1:Archiveall rows from mysql_server to a file:
# pt-archiver--source h=192.168.2.11,D=hellodb,t=students \
--user=root--password=root --file '/root/test.log' \
--where"1=1" --limit 1000 --commit-each --no-check-charset
# cat/root/test.log | pt-align     # 用pt-align对结果进行格式化输出




示例2:Purge(delete) orphan rows from child table:
# pt-archiver--source h=host,D=db,t=child --purge --where 'NOT EXISTS(SELECT * FROM parentWHERE col=child.col)'


pt-diskstats
功能: Aninteractive I/O monitoring tool for GNU/Linux
原理:
和iostat类似,通过获取/proc/diskstats的数值,但是功能更强大。
它能分别输出读、写统计数据,并且有更多的列数据,它是菜单驱动的,交互式的。有很多方式可以聚合数据。
它和pt-stalk一起使用效果更好。

示例:
# pt-diskstats--show-timestamps 【下面是线上的数据库截图】




pt-duplicate-key-checker
功能:
为从mysql表中找出重复的索引和外键,这个工具会将重复的索引和外键都列出来,并生成了删除重复索引的语句。

pt-duplicate-key-checker --help 可以查看帮助

示例:
pt-duplicate-key-checker -uroot-proot -h localhost --databases=b2b -v    #查看b2b数据库的重复索引和外键使用情况




--databases可以接多个数据库,如 --databases=b2b,KF_Mobile,test
--ignore-tables=students # 统计时候可以忽略某张表
--ignore-databases=performance # 统计时候可以统计时候忽略某个数据库
-v 显示详细信息

pt-online-schema-change功能:
功能为在alter操作更改表结构的时候不用锁定表,也就是说执行alter的时候不会阻塞写和读取操作,注意执行这个工具的时候必须做好备份,操作之前最好详细读一下官方文档http://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html。

工作原理:
创建一个和你要执行alter操作的表一样的空表结构,执行表结构修改,然后从原表中copy原始数据到表结构修改后的表,当数据copy完成以后就会将原表移走,用新表代替原表,默认动作是将原表drop掉。在copy数据的过程中,任何在原表的更新操作都会更新到新表,因为这个工具在会在原表上创建触发器,触发器会将在原表上更新的内容更新到新表。如果表中已经定义了触发器这个工具就不能工作了。

示例1:
将hellodb库的students表转为MyISAM存储引擎的
# pt-online-schema-change -uroot -proot -hlocalhost --alter="ENGINE=MyISAM" D=hellodb,t=students --execute


执行上面的命令后执行
> show create tablehellodb.students;





示例2:

# pt-online-schema-change -uroot -proot -hlocalhost  --alter="Add COLUMN AAAINT(4)" D=hellodb,t=students --dry-run
参数:--dry-run 干跑,不实际执行生效
# pt-online-schema-change -uroot -proot -hlocalhost  --alter="Add COLUMN FFINT(4)" D=hellodb,t=students --execute
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  笔记 toolkit percona