Skip to content

Commit

Permalink
fix: 调整mysql对dbha账号的授权方式,统一授权% #6833
Browse files Browse the repository at this point in the history
  • Loading branch information
yksitu committed Sep 11, 2024
1 parent 1b2dddb commit 4f2bed8
Showing 1 changed file with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4f2bed8

Please sign in to comment.