Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
defaultCompression = "gzip"
defaultBegin = "+0"
defaultFrequency = 1440
defaultMaxAllowedPacket = 4194304
defaultMaxAllowedPacket = 4 << 20 // 4 MiB (4194304)
defaultFilenamePattern = core.DefaultFilenamePattern
)

Expand Down Expand Up @@ -136,6 +136,9 @@ func dumpCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, er
if !v.IsSet("max-allowed-packet") && dumpConfig != nil && dumpConfig.MaxAllowedPacket != nil && *dumpConfig.MaxAllowedPacket != 0 {
maxAllowedPacket = *dumpConfig.MaxAllowedPacket
}
if maxAllowedPacket != 0 && maxAllowedPacket != defaultMaxAllowedPacket {
cmdConfig.dbconn.MaxAllowedPacket = maxAllowedPacket
}

// compression algorithm: check config, then CLI/env var overrides
var (
Expand Down
9 changes: 9 additions & 0 deletions cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
}
}

// max-allowed-packet size
maxAllowedPacket := v.GetInt("max-allowed-packet")
if maxAllowedPacket != 0 && maxAllowedPacket != defaultMaxAllowedPacket {
cmdConfig.dbconn.MaxAllowedPacket = maxAllowedPacket
}

// target URL can reference one from the config file, or an absolute one
// if it's not in the config file, it's an absolute one
// if it is in the config file, it's a reference to one of the targets in the config file
Expand Down Expand Up @@ -160,5 +166,8 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
// post-restore scripts
flags.String("post-restore-scripts", "", "Directory wherein any file ending in `.sh` will be run post-restore.")

// max-allowed-packet size
flags.Int("max-allowed-packet", 0, "Maximum size of the buffer for client/server communication, similar to mysql's max_allowed_packet. 0 means to use the default size.")

return cmd, nil
}
14 changes: 9 additions & 5 deletions pkg/database/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
)

type Connection struct {
User string
Pass string
Host string
Port int
MultiStatements bool
User string
Pass string
Host string
Port int
MultiStatements bool
MaxAllowedPacket int

// holds a connection to the database
sql *sql.DB
Expand All @@ -36,6 +37,9 @@ func (c *Connection) MySQL() (*sql.DB, error) {
config.ParseTime = true
config.TLSConfig = "preferred"
config.MultiStatements = c.MultiStatements
if c.MaxAllowedPacket != 0 {
config.MaxAllowedPacket = c.MaxAllowedPacket
}
dsn := config.FormatDSN()
handle, err := sql.Open("mysql", dsn)
if err != nil {
Expand Down