Skip to content

Instantly share code, notes, and snippets.

@geekdenz
Created May 30, 2017 08:27
Show Gist options
  • Save geekdenz/60b18297a1a9f84aa1c1d6743ca8753a to your computer and use it in GitHub Desktop.
Save geekdenz/60b18297a1a9f84aa1c1d6743ca8753a to your computer and use it in GitHub Desktop.
MySQL: Dump all DBs except meta data such as mysql, information_schema and performance_schema.
#!/bin/bash
MYSQL_USER=root
OUT_FILE=$1
MYSQL_PASS=$2
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
DBLIST=""
for DB in `mysql ${MYSQL_CONN} -ANe"${SQL}"`
do
DBLIST="${DBLIST} ${DB}"
done
MYSQLDUMP_OPTIONS="--routines --triggers --single-transaction"
mysqldump ${MYSQL_CONN} ${MYSQLDUMP_OPTIONS} --databases ${DBLIST} > $OUT_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment