# 传统复制在线切换到GTID模式

## 传统复制切换到GTID模式

5.7.6以后参数gtid_mode可以动态修改
GTID_MODE:

• OFF

彻底关闭GTID,如果关闭状态的备库接受到带GTID的事务,则复制中断

• OFF_PERMISSIVE

可以认为是关闭GTID前的过渡阶段,主库在设置成该值后不再生成GTID,备库在接受到带GTID 和不带GTID的事务都可以容忍
主库在关闭GTID时,执行事务会产生一个Anonymous_Gtid事件,会在备库执行:
SET @@SESSION.GTID_NEXT= ‘ANONYMOUS’
备库在执行匿名事务时,就不会去尝试生成本地GTID了

• ON_PERMISSIVE

可以认为是打开GTID前的过渡阶段,主库在设置成该值后会产生GTID,同时备库依然容忍带GTID和不带GTID的事务

• ON

完全打开GTID,如果打开状态的备库接受到不带GTID的事务,则复制中断

1.拓扑中的所有服务器都必须使用MySQL 5.7.6或更高版本. 除非拓扑中的所有服务器都使用此版本,否则无法在任何单个服务器上启用GTID事务.
2.所有服务器都将gtid_mode设置为默认值OFF.

The following procedure can be paused at any time and later resumed where it was, or reversed by jumping to the corresponding step of Section 16.1.5.3, “Disabling GTID Transactions Online”, the online procedure to disable GTIDs. This makes the procedure fault-tolerant because any unrelated issues that may appear in the middle of the procedure can be handled as usual, and then the procedure continued where it was left off.

### 从传统复制模式切换到GTID模式

Important

#### 4.在每个sever执行:

5.在每个服务器上,等待状态变量ONGOING_ANONYMOUS_TRANSACTION_COUNT为零. 可以使用如下方式查询:

ONGOING_ANONYMOUS_TRANSACTION_COUNT显示已标记为匿名的正在进行的事务的数量

6.等待生成到步骤5的所有事务复制到所有服务器. 您可以在不停止更新的情况下执行此操作：唯一重要的是所有anonymous transactions都被复制了.

7.If you use binary logs for anything other than replication, for example point in time backup and restore, wait until you do not need the old binary logs having transactions without GTIDs.

For instance, after step 6 has completed, you can execute FLUSH LOGS on the server where you are taking backups. Then either explicitly take a backup or wait for the next iteration of any periodic backup routine you may have set up.

Ideally, wait for the server to purge all binary logs that existed when step 6 was completed. Also wait for any backup taken before step 6 to expire.

Important
This is the second important point. It is vital to understand that binary logs containing anonymous transactions, without GTIDs cannot be used after the next step. After this step, you must be sure that transactions without GTIDs do not exist anywhere in the topology.

#### 9.在每个sever的my.cnf配置文件中添加

https://yq.aliyun.com/articles/41200

#