This question already has an answer here:

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?

marked as duplicate by Colin 't Hart, Vérace, Paul White Aug 28 '15 at 17:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • No doubt about the possible - it's a dupe! Vote to close and point users to the original answer. – Vérace Aug 28 '15 at 15:51
up vote 28 down vote accepted

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

  • 1
    Just for anyone here reading that is in a similar position to me - you can also just dump everything and manually remove the mysql schema from the dump file, to save time writing/running scripts – Leonard Challis Jul 2 '15 at 11:27
  • 1
    "Why should we care implementing a simple --ignore-database argument, look at this tiny script, it will do just fine." – Gras Double Aug 28 '15 at 4:45
  • 1
    It says 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 9:38
  • 3
    It's always lovely to read the comments :))) – Ivan Nikolchov May 25 '16 at 7:01
  • 2
    @TheStoryCoder It's written in english, but the programming language is bash :D – Denys Vitali Jun 27 '16 at 13:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.