MySQL在线改表工具ghost源码编译与使用方法

gh-ost 是 github开源的MySQL在线改表工具,使用go语言开发,因为没有使用触发器,采用binlog同步增量数据,性能损耗较小,同时也避免了与业务SQL并发执行可能导致的死锁。本文简单介绍gh-ost源码编译安装与使用方法。

一、gh-ost编译安装

1. 前提条件:
go开发环境版本:1.12及以上
go版本升级,参考文章:Linux源码编译安装高版本go语言开发环境

2. 下载gh-ost源码:
git clone https://github.com/github/gh-ost.git

3. 编译:
cd /data/git/gh-ost
./script/build

编译成功后,生成的 gh-ost 可执行文件位于目录:
/data/git/gh-ost/bin/

二、gh-ost使用方法

gh-ost -host=127.0.0.1 -user="user" -password="passwd" -database=" dbname" -table="tablename" -alter="add column c1 varchar(100)" -allow-on-master -ok-to-drop-table -initially-drop-ghost-table -execute