安装方法:
- 下载
wget percona.com/get/percona-toolkit.tar.gz
- 编译安装
tar -zxvf percona-toolkit.tar.gz
cd percona-toolkit-3.0.4
perl Makefile.PL
(若执行Makefile出错 则需先执行yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker)
make
make test
make install
使用场景
pt-online-schema-change –help 可查看参数帮助
若查看参数提示Can’t locate Digest/MD5.pm in @INC错误 则需执行yum -y install perl-Digest-MD5安装相关组件
提示缺少perl-DBI模块,那么直接 yum install perl-DBI
场景1:增加列
pt-online-schema-change --host=192.168.0.0 -uroot -pyourpassword --alter "add column age int(11) default null" D=test,t='test_tb' --execute --print --statistics --no-check-alter
场景2:删除列
pt-online-schema-change --host=192.168.0.0 -uroot -pyourpassword --alter "drop column age" D=test,t='test_tb' --execute --print --statistics --no-check-alter
场景3:更改列
pt-online-schema-change --host=192.168.0.0 -uroot -pyourpassword --alter "CHANGE id id_num int(20)" D=test,t='test_tb' --execute --print --statistics --no-check-alter
场景4:创建索引
pt-online-schema-change --host=192.168.0.0 -uroot -pyourpassword --alter "add index