root@Debian:~# cat dumphelp.sh mysql
DATABASES_TO_EXCLUDE="test"sql
EXCLUSION_LIST="'information_schema','mysql'"ide
for DB in `echo "${DATABASES_TO_EXCLUDE}"`優化
doorm
EXCLUSION_LIST="${EXCLUSION_LIST},'${DB}'"ip
doneit
SQLSTMT="SELECT schema_name FROM information_schema.schemata"io
SQLSTMT="${SQLSTMT} WHERE schema_name NOT IN (${EXCLUSION_LIST})"ast
MYSQLDUMP_DATABASES="--databases"form
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