Check out my latest project: Full Frontal JavaScript Conference

MySQL dump tables like...

mysql $DB -u$USERNAME -p$PASSWORD -e 'show tables like "$LIKE%"' | grep -v Tables_in | xargs mysqldump --add-drop-table $DB -u$USERNAME -p$PASSWORD

Replace dollar variables with your details to drop a group of tables. Useful when you've got one database hosting a number of different web sites and you need a dump of a particular site.

5 Responses to “MySQL dump tables like...”

  1. This is my first code dump entry - I'll be trying to post these whenever I think the code is useful enough to share.

    Note that the $dollar variables should be replaced as appropriate for your table dump.

  2. Thanks!
    Very useful!

  3. Thanks, I needed to export some 200 tables from a 700 table database and I was already looking forward exporting them one by one :(
    As being a newbie it took me some time to figure out that I had to extend your code with > filename to actualy save the mysqldump.

    Regards

  4. mysqldump -h $DBSource -u $USER -p$PASS $DB $TABLE --where='$Field > $VarStart AND $Field $TABLE$DumpName

    Why cant i get this to run in Bash??
    ive tried everything.. Can anyone help??

  5. Hi,

    Great tips (save my life for +/- 150 tables). I've added this options for thme "mysql" command to be more efficient (I hope ;-) :
    -s : silent (no border around the result)
    --skip-column-names : no first line (no need to "grep")

    Regards

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight