From 2f6691a4cd299cce1231fb13de07fee6c6f637e9 Mon Sep 17 00:00:00 2001 From: yksitu <1297650644@qq.com> Date: Tue, 7 Jan 2025 18:32:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(mysql):=20=E4=BF=AE=E5=A4=8Dmysql=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=97=B6=E4=BD=8E=E7=89=88=E6=9C=AC=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E9=97=AE=E9=A2=98=20#8916?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/spiderctl/backend_switch.go | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/spiderctl/backend_switch.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/spiderctl/backend_switch.go index 21ade13ef8..f8592e8158 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/spiderctl/backend_switch.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/spiderctl/backend_switch.go @@ -549,7 +549,12 @@ func (r *SpiderClusterBackendSwitchComp) GrantReplForNewSlave() (err error) { if !ok { return fmt.Errorf("get %s conn failed", swpair.Slave.IpPort()) } - if _, err = conn.ExecMore(r.grantReplSql(swpair.Master.Host)); err != nil { + // 获取版本信息 + ver, err := conn.SelectVersion() + if err != nil { + return err + } + if _, err = conn.ExecMore(r.grantReplSql(swpair.Master.Host, ver)); err != nil { return err } } @@ -570,15 +575,26 @@ func (r *SpiderClusterBackendSwitchComp) StopRepl() (err error) { return nil } -func (r *SpiderClusterBackendSwitchComp) grantReplSql(host string) []string { +func (r *SpiderClusterBackendSwitchComp) grantReplSql(host string, verison string) []string { var execSQLs []string repl_user := r.GeneralParam.RuntimeAccountParam.ReplUser repl_pwd := r.GeneralParam.RuntimeAccountParam.ReplPwd logger.Info("repl user:%s,repl_pwd:%s", repl_user, repl_pwd) - execSQLs = append(execSQLs, fmt.Sprintf("CREATE USER /*!50706 IF NOT EXISTS */ `%s`@`%s` IDENTIFIED BY '%s';", - repl_user, host, repl_pwd)) - execSQLs = append(execSQLs, fmt.Sprintf("GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO `%s`@`%s`;", repl_user, - host)) + if cmutil.MySQLVersionParse(verison) >= cmutil.MySQLVersionParse("5.7") { + // MySQL5.7以上的版本的授权 + execSQLs = append(execSQLs, fmt.Sprintf("CREATE USER /*!50706 IF NOT EXISTS */ `%s`@`%s` IDENTIFIED BY '%s';", + repl_user, host, repl_pwd)) + execSQLs = append(execSQLs, fmt.Sprintf("GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO `%s`@`%s`;", repl_user, + host)) + } else { + // 兼容MySQL5.7以下的版本的授权 + execSQLs = append(execSQLs, + fmt.Sprintf("GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO `%s`@`%s` IDENTIFIED BY '%s';", + repl_user, + host, + repl_pwd)) + } + return execSQLs }