Created
May 30, 2017 08:27
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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