NYCPHP Meetup

NYPHP.org

[nycphp-talk] Re: can mysqldump exclude a database?

Andrew Yochum andrew at digitalpulp.com
Thu Oct 28 23:26:04 EDT 2004


On Thu, Oct 28, 2004 at 11:10:29PM -0400, Faber Fedor wrote:
> On 28/10/04 22:57 -0400, Daniel Convissor wrote:
> > Hey Folks:
> > 
> > mysqldump -A will export all of the databases.  But, what if I want to 
> > exclude a particular database?  Is it possible?  How, please?
> 
> Is there a way to A) list all the databases (databasi?), B) run the
> output through 'grep -v' and then C) mysqldump the result?

Here's some quick bash for that:
    for TABLE in $(echo "show tables" | mysql -u <username> -p'<password>' <database> | grep -v Tables_in_ | grep -v <some_table_to_exclude>)
    do
       mysqldump -u <username> -p'<password>' <database> ${TABLE}
    done

...replace things in angle brackets.  That could certainly be wrapped in a
shell script w/ proper params and stuff, but I'm leaving that to you.

HTH,
Andrew



More information about the talk mailing list