diff --git a/parser/auth/auth.go b/parser/auth/auth.go index 884f11c2f9d5..e086ebfeb517 100644 --- a/parser/auth/auth.go +++ b/parser/auth/auth.go @@ -15,6 +15,7 @@ package auth import ( "fmt" + "github.com/pingcap/tidb/parser/format" ) @@ -62,6 +63,9 @@ func (user *UserIdentity) String() string { // It matches the login user. func (user *UserIdentity) LoginString() string { // TODO: Escape username and hostname. + if user == nil { + return "" + } return fmt.Sprintf("%s@%s", user.Username, user.Hostname) } diff --git a/session/session.go b/session/session.go index decee805527d..63d6e593f49f 100644 --- a/session/session.go +++ b/session/session.go @@ -3295,7 +3295,7 @@ func logGeneralQuery(execStmt *executor.ExecStmt, s *session, isPrepared bool) { } logutil.BgLogger().Info("GENERAL_LOG", zap.Uint64("conn", vars.ConnectionID), - zap.Stringer("user", vars.User), + zap.String("user", vars.User.LoginString()), zap.Int64("schemaVersion", s.GetInfoSchema().SchemaMetaVersion()), zap.Uint64("txnStartTS", vars.TxnCtx.StartTS), zap.Uint64("forUpdateTS", vars.TxnCtx.GetForUpdateTS()),