Skip to content

Commit

Permalink
Set MULTI_RESULTS and MULTI_STATEMENTS MySQL client CAP (#12690)
Browse files Browse the repository at this point in the history
  • Loading branch information
smallinsky committed May 20, 2022
1 parent c65a3f0 commit e92cb47
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/srv/db/mysql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/go-mysql-org/go-mysql/client"
"github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/packet"
"github.com/go-mysql-org/go-mysql/server"
"github.com/gravitational/trace"
Expand Down Expand Up @@ -236,7 +237,14 @@ func (e *Engine) connect(ctx context.Context, sessionCtx *common.Session) (*clie
password,
sessionCtx.DatabaseName,
dialer,
connectOpt)
connectOpt,
// client-set capabilities only.
// TODO(smallinsky) Forward "real" capabilities from mysql client to mysql server.
withClientCapabilities(
mysql.CLIENT_MULTI_RESULTS,
mysql.CLIENT_MULTI_STATEMENTS,
),
)
if err != nil {
if trace.IsAccessDenied(common.ConvertError(err)) && sessionCtx.Database.IsRDS() {
return nil, trace.AccessDenied(`Could not connect to database:
Expand All @@ -255,6 +263,14 @@ take a few minutes to propagate):
return conn, nil
}

func withClientCapabilities(caps ...uint32) func(conn *client.Conn) {
return func(conn *client.Conn) {
for _, cap := range caps {
conn.SetCapability(cap)
}
}
}

// receiveFromClient relays protocol messages received from MySQL client
// to MySQL database.
func (e *Engine) receiveFromClient(clientConn, serverConn net.Conn, clientErrCh chan<- error, sessionCtx *common.Session) {
Expand Down

0 comments on commit e92cb47

Please sign in to comment.