常用GHOST模板

##================================================##
mysql_ip="127.0.0.1"
mysql_port=
ghost_user="root"
ghost_password="123.com"
ghost_database="test1"
ghost_table="tb002"
ghost_command="ADD C4 INT COMMENT '测试列'" ./gh-ost \
--allow-on-master \
--max-load="Threads_running=256" \
--critical-load="Threads_running=512" \
--chunk-size= \
--initially-drop-old-table \
--initially-drop-ghost-table \
--initially-drop-socket-file \
--timestamp-old-table \
--force-table-names="" \
--host="${mysql_ip}" \
--port="${mysql_port}" \
--user="${ghost_user}" \
--password="${ghost_password}" \
--database="${ghost_database}" \
--table="${ghost_table}" \
--alter="${ghost_command}" \
--verbose \
--execute

GHOST常用参数:

、如果希望直接读取主库BINLOG,需要指定allow-on-master参数
、如果想避免上次操作失败产生的临时表导致新操作失败,建议使用initially-drop-ghost-table和initially-drop-socket-file参数
、如果希望GHOST操作完成后删除源表,使用ok-to-drop-table参数
、如果希望GHOST操作完成后保留源表,建议使用timestamp-old-table参数且不使用ok-to-drop-table参数
、使用参数max-load来控制主库繁忙时暂停GHOST运行
、使用参数critical-load来控制主库繁忙时终止GHOST运行
、使用参数throttle-flag-file或throttle-query来控制GHOST暂停运行
、使用参数panic-flag-file来控制GHOST停止运行
、使用参数throttle-control-replicas来控制GHOST对从库复制延迟的影响

GHOST建议:

、避免同一时间允许多个GHOST
、请勿使用GHOST来创建唯一索引
、建议从主库读取BINLOG,执行效率较高
、建议设置critical-load和max-load时仅考虑Threads_running的值,使用Threads_connected容易因连接暴涨导致GHOST暂停或中止
、在磁盘空间足够的条件下,使用timestamp-old-table来保存源表,一方面立即删除源表会造成IO压力,另一方面防止执行中出现BUG或误操作。

GHOST所有参数:

Usage of gh-ost:
-allow-master-master
当运行MM双主模式时需要显示设置。 -allow-nullable-unique-key
设置是否运行唯一键列中使用NULL值,使用ghost创建唯一索引,存在数据丢失风险,慎用! -allow-on-master
当使用主节点的BINLOG来操作时,需要设置该值为ON。 -alter string
修改命令,不包含ALTER TABLE部分。 -approve-renamed-columns ALTER
当使用ghost进行修改列名操作,需要设置该值 -ask-pass
提升输入密码 -assume-master-host string
在双主或多主复制场景下,设置以哪个主节点的BINLOG为主。 -assume-rbr
假定使用基于ROW格式的复制模式 -check-flag
Check if another flag exists/supported. This allows for cross-version scripting. Exits with when all additional provided flags exist, nonzero otherwise. You must provide (dummy) values for flags that require a value. Example: gh-ost --check-flag --cut-over-lock-timeout-seconds --nice-ratio -chunk-size int
设置每个批次复制数据的行数,取值范围100至100000,默认为1000 -concurrent-rowcount
(with --exact-rowcount), when true (default): count rows after row-copy begins, concurrently, and adjust row estimate later on; when false: first count rows, then start row copy (default true)
设置对拷贝记录的计数方式。 -conf string
配置文件的路径 -critical-load string
Comma delimited status-name=threshold, same format as --max-load. When status exceeds threshold, app panics and quits
设置GHOST运行的最大阈值,当超过该阈值后,终止GHOST运行。 -critical-load-hibernate-seconds int
When nonzero, critical-load does not panic and bail out; instead, gh-ost goes into hibernate for the specified duration. It will not read/write anything to from/to any server
当该值不为0时,如果达到critical-load设置的阈值,会休眠指定时间,然后再次检查。 -critical-load-interval-millis int
When , migration immediately bails out upon meeting critical-load. When non-zero, a second check is done after given interval, and migration only bails out if 2nd check still meets critical load
设置达到critical-load设置的阈值后的检查间隔。 -cut-over string
choose cut-over type (default|atomic, two-step) (default "atomic")
设置切换源表和新表表名的操作方式,默认为自动 -cut-over-lock-timeout-seconds int
Max number of seconds to hold locks on tables while attempting to cut-over (retry attempted when lock exceeds timeout) (default )
设置在cut-over时获取表锁的超时时间。 -database string
database name (mandatory)
数据库名 -debug
debug mode (very verbose)
DEBUG模式 -default-retries int
Default number of retries for various operations before panicking (default )
默认重试次数 -discard-foreign-keys
DANGER! This flag will migrate a table that has foreign keys and will NOT create foreign keys on the ghost table, thus your altered table will have NO foreign keys. This is useful for intentional dropping of foreign keys
设置是否丢弃外键,谨慎设置。 -dml-batch-size int
batch size for DML events to apply in a single transaction (range -) (default ) -exact-rowcount
actually count table rows as opposed to estimate them (results in more accurate progress estimation) -execute
actually execute the alter & migrate the table. Default is noop: do some tests and exit
设置运行GHOST操作,默认不执行,仅检查并退出。 -force-named-cut-over
When true, the 'unpostpone|cut-over' interactive command must name the migrated table -force-table-names string
table name prefix to be used on the temporary tables
设置临时表的前缀 -heartbeat-interval-millis int
how frequently would gh-ost inject a heartbeat value (default )
设置检查心跳时间间隔 -help
Display usage -hooks-hint string
arbitrary message to be injected to hooks via GH_OST_HOOKS_HINT, for your convenience -hooks-path string
directory where hook files are found (default: empty, ie. hooks disabled). Hook files found on this path, and conforming to hook naming conventions will be executed -host string
MySQL hostname (preferably a replica, not the master) (default "127.0.0.1") -initially-drop-ghost-table
Drop a possibly existing Ghost table (remains from a previous run?) before beginning operation. Default is to panic and abort if such table exists
设置是否删除已存在的ghost表,默认不删除,如果ghost表存在,则立即退出。 -initially-drop-old-table
Drop a possibly existing OLD table (remains from a previous run?) before beginning operation. Default is to panic and abort if such table exists
设置是否删除已存在的OLD表,默认不删除,如果存在,则立即退出。 -initially-drop-socket-file
Should gh-ost forcibly delete an existing socket file. Be careful: this might drop the socket file of a running migration!
设置是否删除已有的socket文件 -master-password string
MySQL password on master, if different from that on replica. Requires --assume-master-host -master-user string
MySQL user on master, if different from that on replica. Requires --assume-master-host -max-lag-millis int
replication lag at which to throttle operation (default )
设置复制延迟阈值,如果复制延迟超过该阈值,则暂停GHOST操作。 -max-load string
Comma delimited status-name=threshold. e.g: 'Threads_running=100,Threads_connected=500'. When status exceeds threshold, app throttles writes
设置GHOST允许阈值,如果超过该值,则暂停GHOST操作。 -migrate-on-replica
Have the migration run on a replica, not on the master. This will do the full migration on the replica including cut-over (as opposed to --test-on-replica) -nice-ratio float
force being 'nice', imply sleep time per chunk time; range: [0.0..100.0]. Example values: is aggressive. : for every 1ms spent copying rows, sleep additional 1ms (effectively doubling runtime); 0.7: for every 10ms spend in a rowcopy chunk, spend 7ms sleeping immediately after
设置显示GHOST进度的格式 -ok-to-drop-table
Shall the tool drop the old table at end of operation. DROPping tables can be a long locking operation, which is why I'm not doing it by default. I'm an online tool, yes?
设置GHOST完成后是否删除OLD表,对于超大表,删除表操作会持续很长时间,并且造成性能问题,建议将表删除操作放到业务低峰期操作。 -panic-flag-file string
when this file is created, gh-ost will immediately terminate, without cleanup
当GHOST检查到该文件存在时,会立即退出而不做任何清理。 -password string
MySQL password -port int
MySQL port (preferably a replica, not the master) (default ) -postpone-cut-over-flag-file string
while this file exists, migration will postpone the final stage of swapping tables, and will keep on syncing the ghost table. Cut-over/swapping would be ready to perform the moment the file is deleted.
当GHOST检查到该文件存在时,会将切换表名操作延期,直到该文件被删除。 -quiet
quiet
-replica-server-id uint
server id used by gh-ost process. Default: (default )
指定GHOST操作实例的server-id -replication-lag-query string
Deprecated. gh-ost uses an internal, subsecond resolution query
已弃用。 -serve-socket-file string
Unix socket file to serve on. Default: auto-determined and advertised upon startup
指定实例使用的socket文件路径 -serve-tcp-port int
TCP port to serve on. Default: disabled -skip-foreign-key-checks
set to 'true' when you know for certain there are no foreign keys on your table, and wish to skip the time it takes for gh-ost to verify that
忽略外键检查 -skip-renamed-columns ALTER
in case your ALTER statement renames columns, gh-ost will note that and offer its interpretation of the rename. By default gh-ost does not proceed to execute. This flag tells gh-ost to skip the renamed columns, i.e. to treat what gh-ost thinks are renamed columns as unrelated columns. NOTE: you may lose column data
忽略列名修改操作 -stack
add stack trace upon error -switch-to-rbr
let this tool automatically switch binary log format to 'ROW' on the replica, if needed. The format will NOT be switched back. I'm too scared to do that, and wish to protect you if you happen to execute another migration while this one is running
使用GHOST工具修改复制格式为ROW模式 -table string
table name (mandatory)
修改表的表名 -test-on-replica
Have the migration run on a replica, not on the master. At the end of migration replication is stopped, and tables are swapped and immediately swap-revert. Replication remains stopped and you can compare the two tables for building trust
在复制节点上进行测试 -test-on-replica-skip-replica-stop
When --test-on-replica is enabled, do not issue commands stop replication (requires --test-on-replica) -throttle-additional-flag-file string
operation pauses when this file exists; hint: keep default, use for throttling multiple gh-ost operations (default "/tmp/gh-ost.throttle")
当该文件存在时,GHOST操作会暂停,默认值为/tmp/gh-ost.throttle -throttle-control-replicas string
List of replicas on which to check for lag; comma delimited. Example: myhost1.com:,myhost2.com,myhost3.com:
设置要复制延迟的从库 -throttle-flag-file string
operation pauses when this file exists; hint: use a file that is specific to the table being altered
当该文件存在时,GHOST操作会暂停 -throttle-http string
when given, gh-ost checks given URL via HEAD request; any response code other than (OK) causes throttling; make sure it has low latency response
基于HTTP方式来决定GHOST暂停 -throttle-query string
when given, issued (every second) to check if operation should throttle. Expecting to return zero for no-throttle, > for throttle. Query is issued on the migrated server. Make sure this query is lightweight
基于QUERY方式来决定GHOST暂停 -timestamp-old-table
Use a timestamp in old table name. This makes old table names unique and non conflicting cross migrations
GHOST操作完成后,将老表设置带有时间戳 -tungsten
explicitly let gh-ost know that you are running on a tungsten-replication based topology (you are likely to also provide --assume-master-host)
tungsten-replication是一种异构复制技术,如MySQL到MongoDB的复制 -user string
MySQL user -verbose
verbose
设置该参数会导致GHOST输出更多详细信息 -version
Print version & exit

MySQL DDL--ghost执行模板和参数的更多相关文章

  1. MySQL在线DDL gh-ost 使用说明

    背景: 作为一个DBA,大表的DDL的变更大部分都是使用Percona的pt-online-schema-change,本文说明下另一种工具gh-ost的使用:不依赖于触发器,是因为他是通过模拟从库, ...

  2. MySQL DDL执行方式-Online DDL介绍

    1 引言 大家好,今天与大家一起分享一下 mysql DDL执行方式. 一般来说MySQL分为DDL(定义)和DML(操作). DDL:Data Definition Language,即数据定义语言 ...

  3. Mysql的执行计划各个参数详细说明

    执行计划各个参数的说明 1.id 主要是用来标识sql的执行顺序,如果没有子查询,一般来说id只有一个,执行顺序也是从上到下 2.select_type 每个select子句的类型 a:  simpl ...

  4. shell脚本中执行mysql sql脚本文件并传递参数

    1 shell 文件内容替换 sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法. 调用sed命 ...

  5. MySQL DDL详情揭露

    前言: MySQL中DDL语句,即数据定义语言,用于创建.删除.修改.库或表结构,对数据库或表的结构操作.常见的有create,alter,drop等.这类语句通常会耗费很大代价,特别是对于大表做表结 ...

  6. 初识 MySQL 5.6 新功能、参数

    摘要: 继上一篇的文章 初识 MySQL 5.5 新功能.参数 之后,现在MySQL5.6 针对 MySQL5.5 各个方面又提升了很多,特别在性能和一些新参数上面,现在看看大致提升了哪些方面(后续不 ...

  7. MySQL性能优化之max_connections配置参数浅析

    这篇文章主要介绍了MySQL性能优化之max_connections配置参数浅析,本文着重讲解了3种配置max_connections参数的方法,需要的朋友可以参考下 MySQL的max_connec ...

  8. mysql中SQL执行过程详解与用于预处理语句的SQL语法

    mysql中SQL执行过程详解 客户端发送一条查询给服务器: 服务器先检查查询缓存,如果命中了缓存,则立刻返回存储在缓存中的结果.否则进入下一阶段. 服务器段进行SQL解析.预处理,在优化器生成对应的 ...

  9. mysql配置my.cnf文件,以及参数优化提升性能

    系统centos7 mariadb通过yum安装 mysql配置文件位于/etc/my.cnf 常用参数: 1)max_connections设置最大连接(用户)数,其默认值为100,设置太小会出现t ...

随机推荐

  1. Oracle 关联查询

    select count(1),a.policy_id from gp_pol_prod a where a.product_id=8401 group by a.policy_id having c ...

  2. oracle用户的管理

    用户登陆 sql>conn 用户名/密码 给用户修改密码 如果给自己修改密码可以直接使用 sql>password 用户名; 如果给别人修改密码则需要具有dba的权限,或是拥有alter ...

  3. leetcode1

    public class Solution { public int[] TwoSum(int[] nums, int target) { ]; ; i < nums.Length; i++) ...

  4. for 没有作用域的说话

    for i in range(10): passprint(i) 打印的结果就是9 打印的最后一次结果

  5. Delphi中Chrome Chromium、Cef3学习笔记(二)

    原文   http://blog.csdn.net/xtfnpgy/article/details/46635739   用Tchromium替换webbrowser 用惯了EmbeddedWB,不想 ...

  6. SpringBoot +Pom.xml工程资源文件配置

    继承spring-boot-starter-parent 要成为一个spring boot项目,首先就必须在pom.xml中继承spring-boot-starter-parent,同时指定其版本 & ...

  7. html 提取 公用部分

    在写HTML时,总会遇到一些公用部分,如果每个页面都写那就很麻烦,并且代码量大大增加. 网上查询了几种方法: 1.es6 的 embed 标签. <embed src="header. ...

  8. Secondary Indices

    [Secondary Indices] EOSIO has the ability to sort tables by up to 16 indices.  A table's struct cann ...

  9. python爬虫小说代码,可用的

    python爬虫小说代码,可用的,以笔趣阁为例子,python3.6以上,可用 作者的QQ:342290433,汉唐自远工程师 import requests import refrom lxml i ...

  10. 你确定你真的懂Nginx与PHP的交互?

    Nginx是俄国人最早开发的Webserver,现在已经风靡全球,相信大家并不陌生.PHP也通过二十多年的发展来到了7系列版本,更加关注性能.这对搭档在最近这些年,叱咤风云,基本上LNMP成了当下的标 ...