I want to backup all 200+ databases on a MySQL server to all-dbs.sql.
I want to exclude the mysql schema.
How can I do that?
I want to backup all 200+ databases on a MySQL server to all-dbs.sql.
I want to exclude the mysql schema.
How can I do that?
You need to collect all the database names into a space delimited list. Use that for mysqldump
MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
#
# Collect all database names except for
# mysql, information_schema, and performance_schema
#
SQL="SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN"
SQL="${SQL} ('mysql','information_schema','performance_schema')"
DBLISTFILE=/tmp/DatabasesToDump.txt
mysql ${MYSQL_CONN} -ANe"${SQL}" > ${DBLISTFILE}
DBLIST=""
for DB in `cat ${DBLISTFILE}` ; do DBLIST="${DBLIST} ${DB}" ; done
MYSQLDUMP_OPTIONS="--routines --triggers --single-transaction"
mysqldump ${MYSQL_CONN} ${MYSQLDUMP_OPTIONS} --databases ${DBLIST} > all-dbs.sql
Give it a Try !!!
--ignore-database argument, look at this tiny script, it will do just fine."
– Gras Double
Aug 28 '15 at 04:45
mysqldump: unknown option '--ignore-database' don't know why, but when I used --ignore-table=information_schema.* it worked.
– Hussain Behestee
Nov 13 '15 at 09:38
sys database in it that looks like another DB for internal use that should be ignored.
– Stephen Ostermiller
Dec 26 '17 at 18:12
innodb would also need to be added for RDS instances (although it has no actual tables)
– RolandoMySQLDBA
Dec 26 '17 at 18:14
group_concat(schema_name separator ' ') (and make the discussion about EOL characters irrelevant)
– cbmanica
Sep 17 '21 at 01:42
--ignore-database argument we have to rely on complicated scripts as a workaround. The above script is fine, as it's the best we can do…
– Gras Double
Dec 08 '21 at 03:54