MySQL Dumper is a tool for creating filtered and manipulated database dumps. It relies on the SQL native language, using WHERE clauses and complete SELECT statements with aliases. The inspiration for this dumper comes from the MySQL Super Dump
Currently, it supports dumping tables and views.
- Filter by table name (config:
tables
) - Filter by column name (config:
columns
) - Filter by table size (config:
size
) - Replace dumped column values with replacements (config:
replacements
) - Disable data output of specific tables, dump only table data without definitions or completely ignore them (config:
filters
) - Dumping to the file or directly to another database
tables
-key
is a table name andvalue
is a filter (for example:"users": "WHERE id = 1"
)columns
-key
is a column name andvalue
is a filter (for example:"user_id": "WHERE user_id = 1"
). If any table has column that is specified here this filter will be used.size
gt
- value can be any that is acceptable by thehumanize.ParseBigBytes
(link)filters
-key
can be table name or you can specify column name by placing the*.
before column name andvalue
is a filter (for examle:"*.id": "ORDER BY id DESC LIMIT 30"
)
replacements
-key
consists of the table and column name andvalue
is a replacement for the real value (for example:"users.password": "MD5('123456')"
). So you can, for example, hide sensitive data if you are dumping the DB for the developers to use.filters
-key
is table name andvalue
is one of the following:[onlydata, nodata, ignore]
(for example:"logs": "nodata"
) You can also use*
as akey
by which the filter will be applied to all tables that do not match any other filter.
Values in the config are used in the following order:
- table name is checked for existence in the
filters
part of the config. If table name exists and the value is:onlydata
- table definition will not be dumped, but the data will benodata
- table definition will be dumped, but the data won't beignore
- neither definition nor data will be dumped
- table name is checked in the
tables
part of the config. If table name exists, the filter from thevalue
is used for dumping the data. - columns from the table are checked for existence in the
columns
part of the config. The first column that exists in the table column list will be used for dumping the data. - table size will be checked against the value that you set as
gt
value (value that will be compared is(information_schema.tables.data_length + information_schema.tables.index_length)
). Thekey
's under thefilters
are first checked for the table names. If table name exists then thevalue
will be used for dumping the data. If table name does not exist, then column names will be checked. The first column that exists in the table column list will be used for dumping the data. If there is no matching filter, then the default filterORDER BY 1 DESC LIMIT 30
will be used.
{
"tables": {
"users": "WHERE id = 1",
"carts": "WHERE user_id=1 AND item_id=2"
},
"columns": {
"user_id": "WHERE user_id = 1",
"cart_id": "WHERE cart_id = 3"
},
"size": {
"gt": "10 MiB",
"filters": {
"*.id": "ORDER BY id DESC LIMIT 30",
"*.created_at": "ORDER BY created_at DESC LIMIT 30",
"items": "LIMIT 10"
}
},
"replacements": {
"users.password": "MD5('123456')"
},
"filters": {
"table1": "onlydata",
"table2": "nodata",
"table3": "ignore"
}
}
- dump to a file
- dump to Stdout
- dump to another database IMPORTANT:
multiStatements
must be enabled