Skip to content

Commit 0543c43

Browse files
committed
syncer: Refine the mysql configuration item.
1. Separate the configuration of mysql57 and mysql80, remove discarded parameters in mysql8 config. 2. Rename specialConfigs to PluginConfigs.
1 parent 7cad2ca commit 0543c43

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

mysqlcluster/syncer/config_map.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ func NewConfigMapSyncer(cli client.Client, c *mysqlcluster.MysqlCluster) syncer.
5151
return fmt.Errorf("failed to create mysql configs: %s", err)
5252
}
5353

54-
dataSpecial, err := buildMysqlSpecialConf(c)
54+
dataPlugin, err := buildMysqlPluginConf(c)
5555
if err != nil {
56-
return fmt.Errorf("failed to create mysql special configs: %s", err)
56+
return fmt.Errorf("failed to create mysql plugin configs: %s", err)
5757
}
5858
cm.Data = map[string]string{
5959
"my.cnf": data,
60-
utils.SpecialConfig: dataSpecial,
60+
utils.PluginConfigs: dataPlugin,
6161
}
6262

6363
return nil
@@ -70,10 +70,14 @@ func buildMysqlConf(c *mysqlcluster.MysqlCluster) (string, error) {
7070
sec := cfg.Section("mysqld")
7171

7272
c.EnsureMysqlConf()
73-
if c.Spec.MysqlVersion == "8.0" {
74-
delete(mysqlCommonConfigs, "query_cache_size")
75-
delete(mysqlStaticConfigs, "query_cache_type")
73+
74+
switch c.Spec.MysqlVersion {
75+
case "8.0":
76+
addKVConfigsToSection(sec, mysql80Configs)
77+
case "5.7":
78+
addKVConfigsToSection(sec, mysql57Configs)
7679
}
80+
7781
addKVConfigsToSection(sec, mysqlSysConfigs, mysqlCommonConfigs, mysqlStaticConfigs, c.Spec.MysqlOpts.MysqlConf)
7882

7983
if c.Spec.MysqlOpts.InitTokuDB {
@@ -94,12 +98,12 @@ func buildMysqlConf(c *mysqlcluster.MysqlCluster) (string, error) {
9498
return data, nil
9599
}
96100

97-
// Build the Special Cnf file.
98-
func buildMysqlSpecialConf(c *mysqlcluster.MysqlCluster) (string, error) {
101+
// Build the Plugin Cnf file.
102+
func buildMysqlPluginConf(c *mysqlcluster.MysqlCluster) (string, error) {
99103
cfg := ini.Empty(ini.LoadOptions{IgnoreInlineComment: true})
100104
sec := cfg.Section("mysqld")
101105

102-
addKVConfigsToSection(sec, specialConfigs)
106+
addKVConfigsToSection(sec, pluginConfigs)
103107
data, err := writeConfigs(cfg)
104108
if err != nil {
105109
return "", err

mysqlcluster/syncer/variables.go renamed to mysqlcluster/syncer/mysql_configs.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,55 +40,73 @@ var mysqlSysConfigs = map[string]string{
4040
"slave_parallel_type": "LOGICAL_CLOCK",
4141
"relay_log": "/var/lib/mysql/mysql-relay-bin",
4242
"relay_log_index": "/var/lib/mysql/mysql-relay-bin.index",
43-
"master_info_repository": "TABLE",
44-
"relay_log_info_repository": "TABLE",
4543
"slow_query_log": "1",
4644
"tmp_table_size": "32M",
4745
"tmpdir": "/var/lib/mysql",
4846
}
4947

50-
var specialConfigs = map[string]string{
48+
var pluginConfigs = map[string]string{
5149
"plugin-load": "\"semisync_master.so;semisync_slave.so;audit_log.so;connection_control.so\"",
52-
"audit_log_file": "/var/log/mysql/mysql-audit.log",
53-
"audit_log_exclude_accounts": "\"root@localhost,root@127.0.0.1," + utils.ReplicationUser + "@%," + utils.MetricsUser + "@%\"",
54-
"audit_log_buffer_size": "16M",
50+
5551
"rpl_semi_sync_master_enabled": "OFF",
5652
"rpl_semi_sync_slave_enabled": "ON",
5753
"rpl_semi_sync_master_wait_no_slave": "ON",
5854
"rpl_semi_sync_master_timeout": "1000000000000000000",
59-
//"audit-log": "ON",
55+
56+
"audit_log_file": "/var/log/mysql/mysql-audit.log",
57+
"audit_log_exclude_accounts": "\"root@localhost,root@127.0.0.1," + utils.ReplicationUser + "@%," + utils.MetricsUser + "@%\"",
58+
"audit_log_buffer_size": "16M",
6059
"audit_log_policy": "NONE",
6160
"audit_log_rotate_on_size": "104857600",
6261
"audit_log_rotations": "6",
6362
"audit_log_format": "OLD",
63+
6464
"connection_control_failed_connections_threshold": "3",
6565
"connection_control_min_connection_delay": "1000",
6666
"connection_control_max_connection_delay": "2147483647",
67-
"default-authentication-plugin": "mysql_native_password",
67+
}
68+
69+
var mysql57Configs = map[string]string{
70+
"query-cache-type": "0",
71+
"query-cache-size": "0",
72+
"sql-mode": "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER," +
73+
"NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY",
74+
75+
"expire-logs-days": "7",
76+
77+
"master_info_repository": "TABLE",
78+
"relay_log_info_repository": "TABLE",
79+
"slave_rows_search_algorithms": "INDEX_SCAN,HASH_SCAN",
80+
}
81+
82+
var mysql80Configs = map[string]string{
83+
"sql-mode": "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION," +
84+
"NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY",
85+
// 7 days = 7 * 24 * 60 * 60
86+
"binlog_expire_logs_seconds": "604800",
87+
// use 5.7 auth plugin to be backward compatible
88+
"default-authentication-plugin": "mysql_native_password",
6889
}
6990

7091
// mysqlCommonConfigs is the map of the mysql common configs.
7192
var mysqlCommonConfigs = map[string]string{
7293
"character_set_server": "utf8mb4",
7394
"interactive_timeout": "3600",
7495
"default-time-zone": "+08:00",
75-
"expire_logs_days": "7",
7696
"key_buffer_size": "33554432",
7797
"log_bin_trust_function_creators": "1",
7898
"long_query_time": "3",
7999
"binlog_cache_size": "32768",
80100
"binlog_stmt_cache_size": "32768",
81101
"max_connections": "1024",
82102
"max_connect_errors": "655360",
83-
"query_cache_size": "0",
84103
"sync_master_info": "1000",
85104
"sync_relay_log": "1000",
86105
"sync_relay_log_info": "1000",
87106
"table_open_cache": "2000",
88107
"thread_cache_size": "128",
89108
"wait_timeout": "3600",
90109
"group_concat_max_len": "1024",
91-
"slave_rows_search_algorithms": "INDEX_SCAN,HASH_SCAN",
92110
"max_allowed_packet": "1073741824",
93111
"event_scheduler": "OFF",
94112
"innodb_print_all_deadlocks": "0",
@@ -102,12 +120,10 @@ var mysqlCommonConfigs = map[string]string{
102120
// mysqlStaticConfigs is the map of the mysql static configs.
103121
// The mysql need restart, if modify the config.
104122
var mysqlStaticConfigs = map[string]string{
105-
106123
"default-storage-engine": "InnoDB",
107124
"back_log": "2048",
108125
"ft_min_word_len": "4",
109126
"lower_case_table_names": "0",
110-
"query_cache_type": "OFF",
111127
"innodb_ft_max_token_size": "84",
112128
"innodb_ft_min_token_size": "3",
113129
"sql_mode": "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION",

0 commit comments

Comments
 (0)