I have a gigantic database due to having over 1000+ individual tables created for every time someone logged in. (wasnt me that made this).

I want to now create a dump of the database using drush sql-dump but the file ends up to be over 15GB and 1GB zipped.

Is there a quick and easy way to exclude a bunch of tables matching a pattern using drush? The tables I want to exclude all begin with the word "result-<username>"


1 Answer 1


Drush has a number of options to exclude tables from sql-dump. These all now support wildcards (thanks @MPD for pointing this out), so for example you can do this:

drush sql-dump --skip-tables-list='result-*'

This will completely exclude any tables matching the pattern result-* - that is, beginning with result- - from the dump. You can pass multiple patterns (or individual table names) by separating them with commas. The quotes are necessary to prevent your shell from expanding the pattern.

If you want the tables' structure to be included but just not the data in them, use --structure-tables-list instead.

The other options are --skip-tables-key and --structure-tables-key which work similarly, but instead of providing the table names or patterns directly on the command line, you add them to an array in drushrc.php and specify the array key on the command line. This is useful if you have a set of tables that you routinely exclude, such as 'cache_*'. The example.drushrc.php provided with drush gives the following example:

 * List of tables whose *data* is skipped by the 'sql-dump' and 'sql-sync'
 * commands when the "--structure-tables-key=common" option is provided.
 * You may add specific tables to the existing array or add a new element.
# $options['structure-tables']['common'] = array('cache', 'cache_*', 'history', 'search_*', 'sessions', 'watchdog');
  • 1
    Pretty sure when you use the skip-tables option from drushrc.php you can specify a wildcard pattern. But, I have never tried wildcards from the command line.
    – mpdonadio
    Commented Nov 6, 2015 at 2:21
  • Ooh, that's much better. I had no idea that had been added. Commented Nov 6, 2015 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.