mysqldump

package
v0.18.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IgnoreMapPlacement = "ignore"
	NoDataMapPlacement = "nodata"
)

Variables

This section is empty.

Functions

func OpenOutput

func OpenOutput(path string, compression Compression) (io.WriteCloser, string, error)

OpenOutput opens the dump destination. A path of "-" writes to stdout, which is never closed. With compression enabled the returned path carries the compression suffix. The returned writer must be closed to flush the compressor and the file.

Types

type CheckConstraintSchema

type CheckConstraintSchema struct {
	Name       string
	Expression string
}

type ColumnSchema

type ColumnSchema struct {
	Name           string
	Type           string
	CharacterSet   sql.NullString
	Nullable       bool
	Default        sql.NullString
	Extra          string
	Collation      sql.NullString
	Comment        string
	GenerationExpr sql.NullString
	IsVirtual      bool
	CheckExpr      string
}

func (*ColumnSchema) IsBinary

func (c *ColumnSchema) IsBinary() bool

func (*ColumnSchema) IsGenerated

func (c *ColumnSchema) IsGenerated() bool

type Compression

type Compression string

Compression selects how the dump output is compressed.

const (
	CompressionNone Compression = ""
	CompressionGzip Compression = "gzip"
	CompressionZstd Compression = "zstd"
)

func ParseCompression

func ParseCompression(s string) (Compression, error)

ParseCompression validates a user-provided compression name.

type Dumper

type Dumper struct {

	// SelectMap contains column rewrites per table (table -> column -> SQL expression)
	SelectMap map[string]map[string]string
	// WhereMap contains WHERE clauses per table (table -> WHERE clause)
	WhereMap map[string]string
	// NoData contains list of tables to dump structure only (no data), supports glob wildcards (e.g. "cart*")
	NoData []string
	// Ignore contains list of tables to skip entirely, supports glob wildcards (e.g. "cart*")
	Ignore []string
	// LimitMap contains row limits per table (table -> limit). Tables referencing
	// a limited table via foreign keys are filtered automatically.
	LimitMap map[string]TableLimit

	// LockTables controls whether to lock tables during dump (default: true)
	LockTables bool
	// Quick enables quick mode for mysqldump (default: false)
	Quick bool
	// InsertIntoLimit controls how many rows are included in each INSERT statement (default: 100).
	// When set to a positive value, it takes priority over Quick mode.
	// When not set (0 or negative) and Quick is true, the batch size is 1.
	InsertIntoLimit int
	// Parallel controls how many tables to dump concurrently (default: 0 = disabled)
	Parallel int
	// contains filtered or unexported fields
}

func NewMySQLDumper

func NewMySQLDumper(db *sql.DB) *Dumper

NewMySQLDumper creates a new MySQL dumper with default configuration.

func (*Dumper) Dump

func (d *Dumper) Dump(ctx context.Context, w io.Writer) error

Dump creates a MySQL dump and writes it to an io.Writer returns error in the event something gos wrong in the middle of the dump process

type ForeignKeySchema

type ForeignKeySchema struct {
	Name              string
	Columns           []string
	ReferencedTable   string
	ReferencedColumns []string
	OnDelete          string
	OnUpdate          string
}

type IndexColumnSchema

type IndexColumnSchema struct {
	Name    string
	SubPart sql.NullInt64
	Order   string
}

type IndexSchema

type IndexSchema struct {
	Name       string
	Columns    []IndexColumnSchema
	IsUnique   bool
	Type       string
	Comment    string
	SeqInTable int
}

type TableLimit

type TableLimit struct {
	// Maximum amount of rows to export for this table
	Rows int `yaml:"rows" jsonschema:"required,minimum=1"`
	// SQL ORDER BY clause deciding which rows are kept (e.g. "created_at DESC" for the newest rows). Defaults to "created_at DESC" when the table has a created_at column
	OrderBy string `yaml:"order_by,omitempty"`
}

TableLimit restricts how many rows of a table are dumped. All tables referencing the limited table via foreign keys (directly or transitively) are filtered automatically so they only contain rows attached to the kept rows. A second limit on a table that is already filtered this way is rejected. When the limited table references itself (e.g. product.parent_id), the ancestors of the kept rows are dumped too, so the export may hold slightly more than Rows rows but stays importable with foreign key checks enabled.

type TableSchema

type TableSchema struct {
	Name             string
	Engine           string
	Charset          string
	Collation        string
	Comment          string
	RowFormat        string
	AutoIncrement    sql.NullInt64
	Columns          []ColumnSchema
	PrimaryKey       []string
	Indexes          []IndexSchema
	ForeignKeys      []ForeignKeySchema
	CheckConstraints []CheckConstraintSchema
}

func (*TableSchema) BuildCreateTableSQL

func (schema *TableSchema) BuildCreateTableSQL() string

func (*TableSchema) GetBinaryColumns

func (schema *TableSchema) GetBinaryColumns() []string

func (*TableSchema) GetGeneratedColumns

func (schema *TableSchema) GetGeneratedColumns() []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL