Mysql基础——Gtid开启方法
一、Gtid简介
GTID transactions are identified by a global transaction identifier (GTID) in the form UUID:NUMBER. Every GTID transaction in a log is always preceded by a Gtid_log_event. GTID transactions can be addressed using either the GTID or using the file name and position.
Anonymous transactions do not have a GTID assigned, and MySQL ensures that every anonymous transaction in a log is preceded by an Anonymous_gtid_log_event. In previous versions, anonymous transactions were not preceded by any particular event. Anonymous transactions can only be addressed using file name and position.
由于Gtid需要通过数据库参数variables中开启,不然无法显示,开启需要按照顺序开启,不能直接设置为ON;
mysql> SET GLOBAL gtid_mode=ON_PERMISSIVE;
ERROR 1788 (HY000): The value of @@GLOBAL.GTID_MODE can only be changed one step at a time: OFF <-> OFF_PERMISSIVE <-> ON_PERMISSIVE <-> ON. Also note that this value must be stepped up or down simultaneously on all servers. See the Manual for instructions.
二、开启Gtid
1、主库和备库手动开启
mysql> SET GLOBAL gtid_mode=OFF_PERMISSIVE; Query OK, 0 rows affected (0.00 sec) mysql> SET GLOBAL gtid_mode=ON_PERMISSIVE; Query OK, 0 rows affected (0.00 sec) mysql> SET GLOBAL gtid_mode=ON; ERROR 3111 (HY000): SET @@GLOBAL.GTID_MODE = ON is not allowed because ENFORCE_GTID_CONSISTENCY is not ON. mysql> show variables like '%gtid%'; +----------------------------------+---------------+ | Variable_name | Value | +----------------------------------+---------------+ | binlog_gtid_simple_recovery | ON | | enforce_gtid_consistency | OFF | | gtid_executed_compression_period | 1000 | | gtid_mode | ON_PERMISSIVE | | gtid_next | AUTOMATIC | | gtid_owned | | | gtid_purged | | | session_track_gtids | OFF | +----------------------------------+---------------+ 8 rows in set (0.00 sec) mysql> SET GLOBAL enforce_gtid_consistency=ON; Query OK, 0 rows affected (0.00 sec) mysql> SET GLOBAL gtid_mode=ON; Query OK, 0 rows affected (0.01 sec) mysql> show variables like '%gtid%'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | binlog_gtid_simple_recovery | ON | | enforce_gtid_consistency | ON | | gtid_executed_compression_period | 1000 | | gtid_mode | ON | | gtid_next | AUTOMATIC | | gtid_owned | | | gtid_purged | | | session_track_gtids | OFF | +----------------------------------+-----------+ 8 rows in set (0.00 sec)
2、在master节点/etc/my.cnf中【mysqld】添加配置
vim /etc/my.cnf enforce_gtid_consistency=on gtid_mode=on
参考:(38条消息) 书生笔记-gtid_mode 参数解析_魏书生的技术空间的博客-CSDN博客
(38条消息) mysql数据库管理-GTID详解_数据库gtid_执笔画情ora的博客-CSDN博客
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?