安装笔记:在CentOS上安装pt-online-schema-change

yum -y install perl perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-IO-Socket-SSL perl-Digest-MD5

到 https://www.percona.com/downloads/percona-toolkit/LATEST/ 下载并安装:

wget https://www.percona.com/downloads/percona-toolkit/3.1.0/binary/redhat/7/x86_64/percona-toolkit-3.1.0-2.el7.x86_64.rpm
rpm -ivh percona-toolkit-3.1.0-2.el7.x86_64.rpm
rm -f percona-toolkit-3.1.0-2.el7.x86_64.rpm

编写一个脚本 pt.sh

#!/bin/bash
table=$1
alter_conment=$2

cnn_host='127.0.0.1'
cnn_user='root'
cnn_pwd='密码'
cnn_db='kiddo'

echo "$table"
echo "$alter_conment"
/usr/bin/pt-online-schema-change --charset=utf8mb4 --no-version-check --user=${cnn_user} --password=${cnn_pwd} --host=${cnn_host} P=3306,D=${cnn_db},t=$table --alter "${alter_conment}" --execute --nocheck-unique-key-change --no-check-alter
chmod oug+x pt.sh

例子:

./pt.sh rec_reading_record_v2_book "DROP PRIMARY KEY, ADD PRIMARY KEY (id, reading_record_id) PARTITION BY RANGE(reading_record_id) (PARTITION p0 VALUES LESS THAN (10000000), PARTITION p1 VALUES LESS THAN (20000000), PARTITION p2 VALUES LESS THAN (30000000))"

猜你喜欢

转载自www.cnblogs.com/ilovejesus/p/12659271.html