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-keyis a table name andvalueis a filter (for example:"users": "WHERE id = 1")columns-keyis a column name andvalueis a filter (for example:"user_id": "WHERE user_id = 1"). If any table has column that is specified here this filter will be used.sizegt- value can be any that is acceptable by thehumanize.ParseBigBytes(link)filters-keycan be table name or you can specify column name by placing the*.before column name andvalueis a filter (for examle:"*.id": "ORDER BY id DESC LIMIT 30")
replacements-keyconsists of the table and column name andvalueis 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-keyis table name andvalueis one of the following:[onlydata, nodata, ignore](for example:"logs": "nodata") You can also use*as akeyby 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
filterspart 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
tablespart of the config. If table name exists, the filter from thevalueis used for dumping the data. - columns from the table are checked for existence in the
columnspart 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
gtvalue (value that will be compared is(information_schema.tables.data_length + information_schema.tables.index_length)). Thekey's under thefiltersare first checked for the table names. If table name exists then thevaluewill 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 30will 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:
multiStatementsmust be enabled