@@ -329,7 +329,7 @@ func (cfg *Config) buildExtraConfig(filePath string) (*ini.File, error) {
329329 log .Info ("It has remote cluster server-id start offset +100" )
330330 startIndex += mysqlServerIDOffsetInc
331331 }
332- if len (arr ) == 3 && arr [1 ] == "ro" {
332+ if len (arr ) >= 3 && arr [len ( arr ) - 2 ] == "ro" {
333333 log .Info ("It is readonly pod, server-id start offset +100" )
334334 startIndex += mysqlServerIDOffsetInc
335335 }
@@ -426,7 +426,10 @@ func (cfg *Config) buildInitSql(hasInit bool) []byte {
426426 if err != nil {
427427 log .Info ("failed to read /mnt/mysql-cm/init.sql" )
428428 }
429- sql := fmt .Sprintf (`SET @@SESSION.SQL_LOG_BIN=0;
429+ var sql string
430+ if cfg .MySQLVersion .Major == 5 {
431+ log .Info ("version is 5.7, need not donor userq" )
432+ sql = fmt .Sprintf (`SET @@SESSION.SQL_LOG_BIN=0;
430433CREATE DATABASE IF NOT EXISTS %s;
431434DROP user IF EXISTS 'root'@'127.0.0.1';
432435CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '%s';
@@ -446,36 +449,82 @@ GRANT SUPER, PROCESS, RELOAD, CREATE, SELECT ON *.* TO '%s'@'%%';
446449DROP user IF EXISTS '%s'@'%%';
447450CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
448451GRANT ALL ON %s.* TO '%s'@'%%' ;
449- DROP user IF EXISTS '%s'@'%%';
450- CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
451- GRANT BACKUP_ADMIN ON *.* TO '%s'@'%%' ;
452452FLUSH PRIVILEGES;
453453
454454%s
455455` ,
456- cfg .Database , //database
457- cfg .RootPassword ,
458- cfg .InternalRootPassword ,
459- cfg .ReplicationUser , //drop user
460- cfg .ReplicationUser , cfg .ReplicationPassword , //create user
461- cfg .ReplicationUser , //grant REPLICATION
462-
463- cfg .MetricsUser , //drop user MetricsUser
464- cfg .MetricsUser , cfg .MetricsPassword , //create user
465- cfg .MetricsUser , //grant
466-
467- cfg .OperatorUser , //drop user
468- cfg .OperatorUser , cfg .OperatorPassword , //create
469- cfg .OperatorUser , //grant
470-
471- cfg .User , //drop user
472- cfg .User , cfg .Password , //create user
473- cfg .Database , cfg .User , //grant
474- cfg .DonorClone ,
475- cfg .DonorClone , cfg .DonorClonePassword ,
476- cfg .DonorClone , // grant
477- initSQL ,
478- )
456+ cfg .Database , //database
457+ cfg .RootPassword ,
458+ cfg .InternalRootPassword ,
459+ cfg .ReplicationUser , //drop user
460+ cfg .ReplicationUser , cfg .ReplicationPassword , //create user
461+ cfg .ReplicationUser , //grant REPLICATION
462+
463+ cfg .MetricsUser , //drop user MetricsUser
464+ cfg .MetricsUser , cfg .MetricsPassword , //create user
465+ cfg .MetricsUser , //grant
466+
467+ cfg .OperatorUser , //drop user
468+ cfg .OperatorUser , cfg .OperatorPassword , //create
469+ cfg .OperatorUser , //grant
470+
471+ cfg .User , //drop user
472+ cfg .User , cfg .Password , //create user
473+ cfg .Database , cfg .User , //grant
474+ initSQL ,
475+ )
476+ } else {
477+ sql = fmt .Sprintf (`SET @@SESSION.SQL_LOG_BIN=0;
478+ CREATE DATABASE IF NOT EXISTS %s;
479+ DROP user IF EXISTS 'root'@'127.0.0.1';
480+ CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '%s';
481+ GRANT ALL ON *.* TO 'root'@'127.0.0.1' with grant option;
482+ DROP user IF EXISTS 'root'@'%%';
483+ CREATE USER 'root'@'%%' IDENTIFIED BY '%s';
484+ GRANT ALL ON *.* TO 'root'@'%%' with grant option;
485+ DROP user IF EXISTS '%s'@'%%';
486+ CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
487+ GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '%s'@'%%';
488+ DROP user IF EXISTS '%s'@'%%';
489+ CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
490+ GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO '%s'@'%%';
491+ DROP user IF EXISTS '%s'@'%%';
492+ CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
493+ GRANT SUPER, PROCESS, RELOAD, CREATE, SELECT ON *.* TO '%s'@'%%';
494+ DROP user IF EXISTS '%s'@'%%';
495+ CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
496+ GRANT ALL ON %s.* TO '%s'@'%%' ;
497+ DROP user IF EXISTS '%s'@'%%';
498+ CREATE USER '%s'@'%%' IDENTIFIED BY '%s';
499+ GRANT BACKUP_ADMIN ON *.* TO '%s'@'%%' ;
500+ FLUSH PRIVILEGES;
501+
502+ %s
503+ ` ,
504+ cfg .Database , //database
505+ cfg .RootPassword ,
506+ cfg .InternalRootPassword ,
507+ cfg .ReplicationUser , //drop user
508+ cfg .ReplicationUser , cfg .ReplicationPassword , //create user
509+ cfg .ReplicationUser , //grant REPLICATION
510+
511+ cfg .MetricsUser , //drop user MetricsUser
512+ cfg .MetricsUser , cfg .MetricsPassword , //create user
513+ cfg .MetricsUser , //grant
514+
515+ cfg .OperatorUser , //drop user
516+ cfg .OperatorUser , cfg .OperatorPassword , //create
517+ cfg .OperatorUser , //grant
518+
519+ cfg .User , //drop user
520+ cfg .User , cfg .Password , //create user
521+ cfg .Database , cfg .User , //grant
522+ cfg .DonorClone ,
523+ cfg .DonorClone , cfg .DonorClonePassword ,
524+ cfg .DonorClone , // grant
525+ initSQL ,
526+ )
527+ }
479528
480529 if hasInit {
481530 sql += "\n RESET SLAVE ALL;\n "
0 commit comments