Skip to content

Instantly share code, notes, and snippets.

@robgeorgeuk
Created May 22, 2015 17:06
Show Gist options
  • Save robgeorgeuk/8e64c3bcd00040945da9 to your computer and use it in GitHub Desktop.
Save robgeorgeuk/8e64c3bcd00040945da9 to your computer and use it in GitHub Desktop.
Export all MySQL databases in one go
#!/bin/bash
USER="homestead"
PASSWORD="secret"
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
gzip `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