暂无图片
暂无图片
4
暂无图片
暂无图片
暂无图片

pt-online-schema-change在线DDL操作(修改表结构、添加索引等)

原创 鸿惊九天 2022-11-27
628

参数 说明
–alter-foreign-keys-method 检测到外键冲突后会拒绝改表
–[no]check-replication-filters 检测到有复制过滤会拒绝改表
–max-lag 检测到主从复制延迟会自动停止数据拷贝
–max-load 检测到服务器负载过重会暂停操作
–critical-load 检测到服务器负载过重会中断操作
–lock-wait-timeout 设置锁等待超时时间为1s

添加字段
pt-online-schema-change --user=root --password=123456 --host=192.168.200.25 --alter “ADD COLUMN content text” D=aaa,t=tmp_test --no-check-replication-filters --alter-foreign-keys-method=auto --recursion-method=none --print --execute

删除字段
pt-online-schema-change --user=root --password=123456 --host=192.168.200.25 --alter "DROP COLUMN content " D=aaa,t=tmp_test --no-check-replication-filters --alter-foreign-keys-method=auto --recursion-method=none --quiet --execute

修改字段
pt-online-schema-change --user=root --password=123456 --host=192.168.200.25 --alter “MODIFY age TINYINT NOT NULL DEFAULT 0” D=aaa,t=tmp_test --no-check-replication-filters --alter-foreign-keys-method=auto --recursion-method=none --quiet --execute

在线缩小字段示例
–alter “MODIFY ORDER_FROM varchar(128) DEFAULT NULL”

字段改名
pt-online-schema-change --user=root --password=123456 --host=192.168.200.25 --alter “CHANGE COLUMN age address varchar(30)” D=aaa,t=tmp_test --no-check-alter --no-check-replication-filters --alter-foreign-keys-method=auto --recursion-method=none --quiet --execut

增加索引
pt-online-schema-change --user=root --password=123456 --host=192.168.200.25 --alter “ADD INDEX idx_address(address)” D=aaa,t=tmp_test --no-check-alter --no-check-replication-filters --alter-foreign-keys-method=auto --recursion-method=none --print --execute

删除索引
pt-online-schema-change --user=root --password=123456 --host=192.168.200.25 --alter “DROP INDEX idx_address” D=aaa,t=tmp_test --no-check-alter --no-check-replication-filters --alter-foreign-keys-method=auto --recursion-method=none --print --execute

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论