Skip to content

fix mysqldump option #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2019
Merged
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
1 change: 1 addition & 0 deletions canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (c *Canal) prepareDumper() error {
c.dumper.SkipMasterData(c.cfg.Dump.SkipMasterData)
c.dumper.SetMaxAllowedPacket(c.cfg.Dump.MaxAllowedPacketMB)
c.dumper.SetProtocol(c.cfg.Dump.Protocol)
c.dumper.SetExtraOptions(c.cfg.Dump.ExtraOptions)
// Use hex blob for mysqldump
c.dumper.SetHexBlob(true)

Expand Down
3 changes: 3 additions & 0 deletions canal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type DumpConfig struct {

// Set to change the default protocol to connect with
Protocol string `toml:"protocol"`

// Set extra options
ExtraOptions []string `toml:"extra_options"`
}

type Config struct {
Expand Down
11 changes: 11 additions & 0 deletions dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Dumper struct {

IgnoreTables map[string][]string

ExtraOptions []string

ErrOut io.Writer

masterDataSkipped bool
Expand All @@ -59,6 +61,7 @@ func NewDumper(executionPath string, addr string, user string, password string)
d.Databases = make([]string, 0, 16)
d.Charset = DEFAULT_CHARSET
d.IgnoreTables = make(map[string][]string)
d.ExtraOptions = make([]string, 0, 5)
d.masterDataSkipped = false

d.ErrOut = os.Stderr
Expand All @@ -78,6 +81,10 @@ func (d *Dumper) SetWhere(where string) {
d.Where = where
}

func (d *Dumper) SetExtraOptions(options []string) {
d.ExtraOptions = options
}

func (d *Dumper) SetErrOut(o io.Writer) {
d.ErrOut = o
}
Expand Down Expand Up @@ -185,6 +192,10 @@ func (d *Dumper) Dump(w io.Writer) error {
args = append(args, fmt.Sprintf("--where=%s", d.Where))
}

if len(d.ExtraOptions) != 0 {
args = append(args, d.ExtraOptions...)
}

if len(d.Tables) == 0 && len(d.Databases) == 0 {
args = append(args, "--all-databases")
} else if len(d.Tables) == 0 {
Expand Down