root@Debian:~# cat dumphelp.sh 

DATABASES_TO_EXCLUDE="test"

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 -uroot -ANe"${SQLSTMT}"`

do

    MYSQLDUMP_DATABASES="${MYSQLDUMP_DATABASES} ${DB}"

done

MYSQLDUMP_OPTIONS="--single-transaction --skip-opt --create-options  --master-data=2 -q -uroot --default-character-set=utf8"

mysqldump ${MYSQLDUMP_OPTIONS} ${MYSQLDUMP_DATABASES} > MySQLDatabases.sql


上述脚本参数-B mysql做了限制1024 ,所以对脚本进行了优化。现在可以导出超过1024个库的mysql


DATABASES_TO_EXCLUDE="test,performance_schema"

EXCLUSION_LIST="'information_schema','mysql',test"

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"

MYSQLDUMP_OPTIONS="--single-transaction --skip-opt --create-options  --master-data=2 -q -uroot --default-character-set=utf8"

for DB in `mysql -uroot -ANe"${SQLSTMT}"`

do

        mysqldump ${MYSQLDUMP_OPTIONS} $MYSQLDUMP_DATABASES $DB >> MySQLDatabases.sql

done