slimdump
slimdump
slimdump
is a little tool to help you create configurable dumps of large MySQL-databases. It works off one or several configuration files. For every table you specify, it can dump only the schema (CREATE TABLE ...
statement), full table data, data without blobs and more.
Why?
We created slimdump
because we often need to dump parts of MySQL databases in a convenient and reproducible way. Also, when you need to analyze problems with data from your production databases, you might want to pull only relevant parts of data and hide personal data (user names, for example).
mysqldump
is a great tool, probably much more proven when it comes to edge cases and with a lot of switches. But there is no easy way to create a simple configuration file that describes a particular type of dump (e.g. a subset of your tables) and share it with your co-workers. Let alone dumping tables and omitting BLOB type columns.
Installation
When PHP is your everyday programming language, you probably have Composer installed. You can then easily install slimdump
as a global package. Just run composer global require webfactory/slimdump
. In order to use it like any other Unix command, make sure $COMPOSER_HOME/vendor/bin
is in your $PATH
.
Of course, you can also add slimdump
as a local (per-project) Composer dependency.
We’re also working on providing a .phar
package of slimdump
for those not using PHP regularly. With that solution, all you need is to have the PHP interpreter installed and to download a single archive file to use slimdump
. You can help us and open a pull request for that :-)!
Usage
slimdump
needs the DSN for the database to dump and one or more config files:
slimdump {DSN} {config-file} [...more config files...]
slimdump
writes to STDOUT. If you want your dump written to a file, just redirect the output:
slimdump {DSN} {config-file} > dump.sql
If you want to use an environment variable for the DSN, replace the first parameter with -
:
MYSQL_DSN={DSN} slimdump - {config file(s)}
The DSN has to be in the following format:
mysql://[user[:password]@]host[:port]/dbname
For further explanations have a look at the Doctrine documentation.
Optional parameters and command line switches
no-progress
This turns off printing some progress information on stderr
. Useful in scripting contexts.
Example:
slimdump --no-progress {DSN} {config-file}
buffer-size
You can also specify the buffer size, which can be useful on shared environments where your max_allowed_packet
is low.
Do this by using the optional cli-option buffer-size
. Add a suffix (KB, MB or GB) to the value for better readability.
Example:
slimdump --buffer-size=16MB {DSN} {config-file}
single-line-insert-statements
If you have tables with a large number of rows to dump and you are not planning to keep your dumps under version
control, you might consider writing each INSERT INTO
-statement to a single line instead of one line per row. You can
do this by using the cli-parameter single-line-insert-statements
. This can speed up the import significantly.
Example:
slimdump --single-line-insert-statements {DSN} {config-file}
output-csv
This option turns on the CSV (comma separated values) output mode. It must be given the path to a directory where .csv
files will be created. The files are named according to tables, e. g. my_table.csv
.
CSV files contain only data. They are not created for views, triggers, or tables dumped with the schema
dump mode. Also, no files will be created for empty tables.
Since this output format needs to write to different files for different tables, redirecting stdout
output (as can be done for the default MySQL SQL mode) is not possible.
Experimental Feature CSV support is a new, experimental feature. The output formatting may change at any time.
Configuration
Configuration is stored in XML format somewhere in your filesystem. As a benefit, you could add the configuration to your repository to share a quickstart to your database dump with your coworkers.
Example: