[mysqld] # --- 1. 基础网络与端口配置 --- user = mysql port = 3306 bind-address = 0.0.0.0 mysqlx-port = 33060 mysqlx-bind-address = 0.0.0.0 # --- 2. 目录路径配置 --- # 注意:容器内路径。确保 Docker volumes 挂载了这些位置 datadir = /var/lib/mysql log-error = /var/log/mysql/error.log secure-file-priv= /var/lib/mysql-files # --- 3. 基础性能与存储引擎 --- default_storage_engine = InnoDB disabled_storage_engines = "MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,EXAMPLE" # --- 4. 事务与复制核心配置 (MGR 强制要求) --- server_id = 3 gtid_mode = ON enforce_gtid_consistency = ON binlog_format = ROW log_slave_updates = ON binlog_checksum = NONE master_info_repository = TABLE relay_log_info_repository = TABLE transaction_write_set_extraction = XXHASH64 # --- 5. MGR (Group Replication) 专项配置 --- plugin_load_add = 'group_replication.so' # 使用 loose- 前缀避免启动时的未知变量错误 # 集群唯一标识 (必须是标准 UUID) loose-group_replication_group_name="235e4553-3508-46c2-b3a3-768fc0c829e2" # 节点间同步数据的通信地址(建议使用容器固定 IP) loose-group_replication_local_address = "192.168.0.213:33061" # 集群种子节点地址列表 loose-group_replication_group_seeds = "192.168.0.211:33061,192.168.0.212:33061,192.168.0.213:33061" # 启动行为 loose-group_replication_start_on_boot = OFF loose-group_replication_bootstrap_group = OFF # 模式配置 (推荐单主模式) loose-group_replication_single_primary_mode = ON loose-group_replication_enforce_update_everywhere_checks = OFF # --- 6. 日志与超时优化 --- slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 2 interactive_timeout = 28800 wait_timeout = 28800 # 限制 binlog 的总大小或保留天数(MySQL 8.0 推荐使用天数变量), 7天 = 7 * 24 * 3600 秒,过期自动删除 binlog_expire_logs_seconds = 604800 # 限制单个 binlog 文件的大小 max_binlog_size = 500M