安装
下载安装包:
安装: rpm -ivh gh-ost-1.1.7-1.x86_64.rpm
可执行的条件:
- 参数default_storage_engine的值为InnoDB
- 参数binlog_format的值为ROW
库内创建用户
---已有相同权限的用户,可以直接使用
create user ghost@'110.%' identified by 'ghost';
grant ALL PRIVILEGES on . to ghost@'110.%';
flush privileges;
执行示例
--直接连接主库为例
腾讯云环境
--测试是否可行
gh-ost \
--host=10.112.8.126 \
--port=3306 \
--user="root" \
--password="xxx" \
--database="wechat2" \
--table="flow_flow" \
--alter='ADD COLUMN submitDate bigint GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(`$json`, "$.form.submitDate"))) STORED, ADD COLUMN title text GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(`$json`, "$.form.title"))) STORED, ADD COLUMN submitterId varchar(100) GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(`$json`, "$.form.submitterId"))) STORED' \
--aliyun-rds \
--allow-on-master \
--panic-flag-file=/tmp/ghost-panic.flag \
--verbose
--正式执行
nohup gh-ost \
--host=10.112.8.1 \
--port=3306 \
--user="root" \
--password="xxx" \
--database="wechat2" \
--table="flow_flow" \
--alter='ADD COLUMN submitDate bigint GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(`$json`, "$.form.submitDate"))) STORED, ADD COLUMN title text GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(`$json`, "$.form.title"))) STORED, ADD COLUMN submitterId varchar(100) GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(`$json`, "$.form.submitterId"))) STORED' \
--aliyun-rds \
--allow-on-master \
--panic-flag-file=/tmp/ghost-panic.flag \
--execute >gh-ost-flow_flow.log 2>&1 &
注意:
- 阿里云/腾讯云/华为云上都需要制定参数--aliyun-rds
- 主节点上读binlog 参数--allow-on-master
- 随时停止参数--panic-flag-file
- 若报错FATAL Unexpected database port reported: 3388(或其他端口),增加参数--assume-master-host=" 10.112.8.1 : 3388"
- --host要写只写节点的IP,不能是可读可写的proxy IP。
结尾:
全部为真实测试遇到的问题,如有没有涉及到的,大家可补充。