From 4f2bed8e2ad1bdc9b186acb9edaed67557b9a20f Mon Sep 17 00:00:00 2001 From: yksitu <1297650644@qq.com> Date: Wed, 11 Sep 2024 11:06:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4mysql=E5=AF=B9dbha?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E7=9A=84=E6=8E=88=E6=9D=83=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E7=BB=9F=E4=B8=80=E6=8E=88=E6=9D=83%=20#6833?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pkg/components/mysql/install_mysql.go | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/install_mysql.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/install_mysql.go index b055439ce1..8fc4a06d42 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/install_mysql.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/install_mysql.go @@ -828,33 +828,29 @@ func (a *AdditionalAccount) GetWEBCONSOLERSAccount(realVersion string) (initAcco // GetDBHAAccount TODO // 获取生成DHBA-GM访问账号的生成语句 +// 统一给%授权 func (a *AdditionalAccount) GetDBHAAccount(realVersion string) (initAccountsql []string) { - for _, host := range cmutil.RemoveDuplicate(a.AccessHosts) { - if cmutil.MySQLVersionParse(realVersion) >= cmutil.MySQLVersionParse("5.7.18") { - initAccountsql = append(initAccountsql, - fmt.Sprintf("CREATE USER IF NOT EXISTS '%s'@'%s' IDENTIFIED WITH mysql_native_password BY '%s' ;", - a.User, host, a.Pwd)) - initAccountsql = append(initAccountsql, fmt.Sprintf( - "GRANT RELOAD, PROCESS, SHOW DATABASES, SUPER, REPLICATION CLIENT, SHOW VIEW "+ - "ON *.* TO '%s'@'%s' WITH GRANT OPTION ;", - a.User, host)) - } else { - initAccountsql = append(initAccountsql, - fmt.Sprintf( - "GRANT RELOAD, PROCESS, SHOW DATABASES, SUPER, REPLICATION CLIENT, SHOW VIEW "+ - "ON *.* TO '%s'@'%s' IDENTIFIED BY '%s' WITH GRANT OPTION ;", - a.User, host, a.Pwd)) - } - + if cmutil.MySQLVersionParse(realVersion) >= cmutil.MySQLVersionParse("5.7.18") { initAccountsql = append(initAccountsql, - fmt.Sprintf( - "GRANT SELECT, INSERT, DELETE ON `infodba_schema`.* TO '%s'@'%s' ;", - a.User, host)) - + fmt.Sprintf("CREATE USER IF NOT EXISTS '%s'@'%%' IDENTIFIED WITH mysql_native_password BY '%s' ;", + a.User, a.Pwd)) + initAccountsql = append(initAccountsql, fmt.Sprintf( + "GRANT RELOAD, PROCESS, SHOW DATABASES, SUPER, REPLICATION CLIENT, SHOW VIEW "+ + "ON *.* TO '%s'@'%%' WITH GRANT OPTION ;", + a.User)) + } else { initAccountsql = append(initAccountsql, fmt.Sprintf( - " GRANT SELECT ON `mysql`.* TO '%s'@'%s' ;", a.User, host)) + "GRANT RELOAD, PROCESS, SHOW DATABASES, SUPER, REPLICATION CLIENT, SHOW VIEW "+ + "ON *.* TO '%s'@'%%' IDENTIFIED BY '%s' WITH GRANT OPTION ;", + a.User, a.Pwd)) } + + initAccountsql = append(initAccountsql, + fmt.Sprintf("GRANT SELECT, INSERT, DELETE ON `infodba_schema`.* TO '%s'@'%%' ;", a.User)) + + initAccountsql = append(initAccountsql, + fmt.Sprintf(" GRANT SELECT ON `mysql`.* TO '%s'@'%%' ;", a.User)) return }