Skip to content

Instantly share code, notes, and snippets.

@anthonybudd
Created January 22, 2018 17:25
Show Gist options
  • Save anthonybudd/b4020b80c4e28796df3ca8304a9bc18b to your computer and use it in GitHub Desktop.
Save anthonybudd/b4020b80c4e28796df3ca8304a9bc18b to your computer and use it in GitHub Desktop.
Simple shell script to dump a whole MySQL instance to files
#!/bin/bash
USER="root"
PASSWORD="root"
OUTPUT="/Users/anthonybudd/sql/backup"
databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db"
mysqldump -u $USER -p$PASSWORD --databases $db > `date +%Y%m%d`.$db.sql
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment