diff --git a/executor/set.go b/executor/set.go index e4372cc2dd2d1..c17cb5c085fa8 100644 --- a/executor/set.go +++ b/executor/set.go @@ -189,7 +189,13 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e valStr, err = value.ToString() terror.Log(errors.Trace(err)) } - logutil.Logger(context.Background()).Info("set session var", zap.Uint64("conn", sessionVars.ConnectionID), zap.String("name", name), zap.String("val", valStr)) + if name != variable.AutocommitVar { + logutil.Logger(context.Background()).Info("set session var", zap.Uint64("conn", sessionVars.ConnectionID), zap.String("name", name), zap.String("val", valStr)) + } else { + // Some applications will set `autocommit` variable before query. + // This will print too many unnecessary log info. + logutil.Logger(context.Background()).Debug("set session var", zap.Uint64("conn", sessionVars.ConnectionID), zap.String("name", name), zap.String("val", valStr)) + } } return nil diff --git a/server/conn.go b/server/conn.go index 2a8e5e6459e84..e04f4d3861346 100644 --- a/server/conn.go +++ b/server/conn.go @@ -111,7 +111,7 @@ type clientConn struct { func (cc *clientConn) String() string { collationStr := mysql.Collations[cc.collation] - return fmt.Sprintf("id:%d, addr:%s status:%d, collation:%s, user:%s", + return fmt.Sprintf("id:%d, addr:%s status:%b, collation:%s, user:%s", cc.connectionID, cc.bufReadConn.RemoteAddr(), cc.ctx.Status(), collationStr, cc.user, ) } @@ -394,6 +394,20 @@ func (cc *clientConn) readOptionalSSLRequestAndHandshakeResponse(ctx context.Con return errors.Trace(err) } +func (cc *clientConn) SessionStatusToString() string { + status := cc.ctx.Status() + inTxn, autoCommit := 0, 0 + if status&mysql.ServerStatusInTrans > 0 { + inTxn = 1 + } + if status&mysql.ServerStatusAutocommit > 0 { + autoCommit = 1 + } + return fmt.Sprintf("inTxn:%d, autocommit:%d", + inTxn, autoCommit, + ) +} + func (cc *clientConn) openSessionAndDoAuth(authData []byte) error { var tlsStatePtr *tls.ConnectionState if cc.tlsConn != nil { @@ -520,6 +534,8 @@ func (cc *clientConn) Run(ctx context.Context) { } logutil.Logger(ctx).Warn("dispatch error", zap.String("connInfo", cc.String()), + zap.String("command", mysql.Command2Str[data[0]]), + zap.String("status", cc.SessionStatusToString()), zap.String("sql", queryStrForLog(string(data[1:]))), zap.String("err", errStrForLog(err)), )