Call us Toll-Free:
1-800-218-1525
Email us

 Sponsors

mysqldump exclude databases

Mike Peters, 01-18-2015
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

#!/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

Patrick McCarthy, 03-21-2016
Finally a script that works!!!
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions