my2.cnf 2.1 KB

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