Centos使用MySQL工具Percona Toolkit
安装Percona Toolkit 的Repo 得以支持直接用yum 安装二进制包
yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm yum install -y percona-toolkit
改MySQL表结构DDL pt-online-schema-change
pt-online-schema-change -u root -h 10.8.8.8 -p password --alter='add column vid int ' --execute A=utf8,D=database,t=table
D=database 库名
t=table 表名
–alter=’add column vid int ‘ 要执行的语句
注意:
mysql版本5.5 数据库和表都是utf8编码,
表的字段注释维中文
在执行 pt-online-schema-change的时候一定的加参数 -A=utf-8
Operation, tries, wait: copy_rows, 10, 0.25 create_triggers, 10, 1 drop_triggers, 10, 1 swap_tables, 10, 1 update_foreign_keys, 10, 1 Altering `wwek`.`wwek_users`... Creating new table... Created new table wwek._wwek_users_new OK. Altering new table... Altered `wwek`.`_wwek_users_new` OK. 2015-09-18T10:56:16 Creating triggers... 2015-09-18T10:56:16 Created triggers OK. 2015-09-18T10:56:16 Copying approximately 183066 rows... Copying `wwek`.`wwek_users`: 30% 01:10 remain Copying `wwek`.`wwek_users`: 49% 01:01 remain Copying `wwek`.`wwek_users`: 63% 00:51 remain Copying `wwek`.`wwek_users`: 76% 00:37 remain Copying `wwek`.`wwek_users`: 88% 00:20 remain 2015-09-18T10:59:03 Copied rows OK. 2015-09-18T10:59:03 Swapping tables... 2015-09-18T10:59:03 Swapped original and new tables OK. 2015-09-18T10:59:03 Dropping old table... 2015-09-18T10:59:04 Dropped old table `wwek`.`_wwek_users_old` OK. 2015-09-18T10:59:04 Dropping triggers... 2015-09-18T10:59:04 Dropped triggers OK. Successfully altered `wwek`.`wwek_users`.