Mysqldump selected tables

The fine fine art of command line programming keeps suprising me, it’s brilliant what you can acomplish with a few lines of commands all mixed up in grep and other linux commands.I’m working on a huge wordpress mu project and have run into problems with upgrading from version 1.1.1 to the latest version (currently 2.7), so now I decided to move some of the data to my laptop and try to recreate the problems. But I do not want to move all ~20 GB data since I only need a few blogs for testing.

I googled the task and found a mix of options, after a few minutes of testing I came up with this lovely little commandline:

mysql databasename -u [root] -p[password] -e 'show tables like "wp_153_%"' | grep -v Tables_in
| xargs mysqldump [databasename] -u [root] -p[password] > [target_file]

Beauty full isn’t it :)

It will grap all tables containing “wp_153_*” and dump this into your target file.

About these ads

Posted in Linux

Tags:

Permalink 20 Comments

20 responses to “Mysqldump selected tables

  1. Nizzy

    Awesome man! Indeed, it’s beatiful.

  2. This was really beautiful! This saved my day. Thank you.

  3. Pingback: Några tips för att flytta och byta url på en Wordpress-installationU - Swedmedia Utveckling | Internet, trender & analyser

  4. Manoj Kumar V

    Hi
    Can u please tell me how do i restore selected tables only from a mysqldump file?

    Regards
    Manoj Kumar V

  5. Jacek

    As far as I know mysqldump supports multiple tables dump like so:

    mysqldump -u{user} -p {database} {table1} {table2} {table3} > destination

    Way easier ,no ?

  6. krickzz

    You fix the errors and try again until no errors found.

  7. a

    xargs is my favorite

  8. Stan

    Thanks! Exactly what I was looking for.

  9. sathik

    Thanks a lot. I am new to sql , please explain the syntax

  10. SV

    That’s cool, thanks

  11. MiZi

    mysql databasename -u [root] -p[password] —disable-column-names -e ‘show tables like “wp_153_%”‘ | xargs mysqldump [databasename] -u [root] -p[password] > [target_file]

    if use “—disable-column-names” – “grep -v Tables_in” is not needed

  12. courntey

    im getting the “xargs: mysqldump: No such file or directory” error. Here is my code…

    ./mysql sfc_current -u root -p -e ‘show tables like “civicrm%”‘ | grep -v Tables_in | xargs mysqldump sfc_current -u root -p > /Users/work/Desktop/civicrm_dump1.sql

  13. nice site, spread the truth about the Olympic 2012 false-flag terror attacks due to take place in london because US/UK/EU/Isreal is running out of excuses to attack Iran/Syria. Thanks mate. Appreciate it =)

  14. Saravana

    How to take selected column in a table using Mysql

  15. For reference, this may be help someone:

    The “-B” or “–batch” option will force the output to be TAB delimited no matter where the output is going. The “-N” option will turn off column names in the output.

    via noah.org

  16. I really had been researching for tips for my personal blog site and came across
    your own posting, “Mysqldump selected tables | Kristian Nissen”,
    will you mind in cases where I make use of some of your ideas?
    I am grateful -Tiffani

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

the dojo

twits

RSS Fork me…

  • An error has occurred; the feed is probably down. Try again later.
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: