iferr:=excSQL(app.ContainerName,app.Password,fmt.Sprintf("create user '%s'@'%s' identified by '%s';",req.Username,tmpPermission,req.Password));err!=nil{
iferr:=excuteSql(app.ContainerName,app.Password,fmt.Sprintf("drop user if exists '%s'@'%s'",mysql.Username,mysql.Permission));err!=nil{
returnerr
varuserlist[]string
ifstrings.Contains(mysql.Permission,","){
userlist=strings.Split(mysql.Permission,",")
}else{
userlist=append(userlist,mysql.Permission)
}
ifinfo.ID==0{
returnnil
for_,user:=rangeuserlist{
iflen(user)!=0{
iferr:=excuteSql(app.ContainerName,app.Password,fmt.Sprintf("drop user if exists '%s'@'%s'",mysql.Username,user));err!=nil{
returnerr
}
}
iferr:=excuteSql(app.ContainerName,app.Password,fmt.Sprintf("create user if not exists '%s'@'%s' identified by '%s';",mysql.Username,info.Value,mysql.Password));err!=nil{
returnerr
}
grantStr:=fmt.Sprintf("grant all privileges on `%s`.* to '%s'@'%s'",mysql.Name,mysql.Username,info.Value)
ifmysql.Name=="*"{
grantStr=fmt.Sprintf("grant all privileges on *.* to '%s'@'%s'",mysql.Username,info.Value)
ifinfo.ID==0{
returnnil
}
ifapp.Version=="5.7.39"{
grantStr=fmt.Sprintf("%s identified by '%s' with grant option;",grantStr,mysql.Password)