From ee2fbc2e902c5cd81a69781c5bfadf3ec3b655cd Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Thu, 26 Mar 2026 18:19:50 +0800 Subject: [PATCH] fix: mysql grant with passwd --- pkg/util/mysql/mysql.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/util/mysql/mysql.go b/pkg/util/mysql/mysql.go index 84c433de2..38645dfbd 100644 --- a/pkg/util/mysql/mysql.go +++ b/pkg/util/mysql/mysql.go @@ -187,7 +187,7 @@ func (conn *Connection) Grant(username string, password string, database string, database = "*" } { - sql := fmt.Sprintf("CREATE USER '%s'@'%s' IDENTIFIED BY '%s'", username, address, password) + sql := fmt.Sprintf("CREATE USER IF NOT EXISTS '%s'@'%s' IDENTIFIED BY '%s'", username, address, password) _, err := conn.db.Exec(sql) if err != nil { return errors.Wrap(err, sql) @@ -199,6 +199,7 @@ func (conn *Connection) Grant(username string, password string, database string, if err != nil { return errors.Wrap(err, sql) } + conn.db.Exec("FLUSH PRIVILEGES") } return nil }