Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

mysqldump exclude databases

mysqldump doesn't offer an option to exclude a database from the dump, similar to --ignore-table for tables

Bash to the rescue!

This short shell script lets you exclude a list of databases

Code:

#!/bin/bash
DATABASES_TO_EXCLUDE="EXCLUDEDB1 EXCLUDEDB2"
EXCLUSION_LIST="'information_schema','mysql'"
for DB in `echo "${DATABASES_TO_EXCLUDE}"`
do
    EXCLUSION_LIST="${EXCLUSION_LIST},'${DB}'"
done
SQLSTMT="SELECT schema_name FROM information_schema.schemata"
SQLSTMT="${SQLSTMT} WHERE schema_name NOT IN (${EXCLUSION_LIST})"
MYSQLDUMP_DATABASES="--databases"
for DB in `mysql -hHOST -uUSER -pPASSWORD -ANe"${SQLSTMT}"`
do
    MYSQLDUMP_DATABASES="${MYSQLDUMP_DATABASES} ${DB}"
done
MYSQLDUMP_OPTIONS="--routines --triggers --events -hHOST -uUSER -pPASSWORD "
mysqldump ${MYSQLDUMP_OPTIONS} ${MYSQLDUMP_DATABASES} > dump.sql



This post first appeared on Recent Posts - Software Projects Inc., please read the originial post: here

Share the post

mysqldump exclude databases

×

Subscribe to Recent Posts - Software Projects Inc.

Get updates delivered right to your inbox!

Thank you for your subscription

×