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.

[I’ve published 38 videos for new developers, designers, UX, UI, product owners and anyone who needs to conquer the command line today.](https://training.leftlogic.com/buy/terminal/cli2?coupon=BLOG\&utm_source=blog\&utm_medium=banner\&utm_campaign=remysharp-discount)

Published 16-Sep 2007 under #code & #mysql & #shell-script-bash. [Edit this post](https://github.com/remy/remysharp.com/blob/main/public/blog/mysql-dump-tables-like.md)

Comments

Lock Thread

Login

Add Comment[M ↓   Markdown]()

[Upvotes]()[Newest]()[Oldest]()

?

Anonymous

0 points

13 years ago

coincidence!

I was just looking to do this!

Cheers Rem.

?

Anonymous

0 points

13 years ago

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

?

Anonymous

0 points

14 years ago

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??

?

Anonymous

0 points

15 years ago

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

?

Anonymous

0 points

15 years ago

Thanks!\ Very useful!

rem

0 points

16 years ago

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.

[Commento](https://commento.io)