---

title: MySQL 零停机表结构变更:gh-ost 与 pt-online-schema-change

keywords:

  • gh-ost
  • pt-online-schema-change
  • 在线DDL
  • 迁移
  • 主从

description: 使用 gh-ost 或 pt-online-schema-change 在生产环境进行在线表结构变更,提供命令示例与验证要点。

tags:

  • MySQL
  • gh-ost
  • pt-online-schema-change
  • 主从
  • 在线DDL
  • 数据库
  • 迁移
  • 运维

categories:

  • 文章资讯
  • 编程技术

---

MySQL 零停机表结构变更:gh-ost 与 pt-online-schema-change

gh-ost 示例

gh-ost \
  --host=127.0.0.1 --port=3306 \
  --user=root --password=secret \
  --database=app --table=items \
  --alter="ADD COLUMN category VARCHAR(64) NULL" \
  --execute

pt-online-schema-change 示例

pt-online-schema-change \
  --alter "ADD INDEX idx_name(name)" \
  D=app,t=items --execute

验证与注意

  • 确认外键与触发器影响
  • 在从库或影子表验证后再执行生产
  • 观察复制延迟与回放情况

总结

在线 DDL 工具能在高可用场景下平滑变更,需严格演练与监控。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部