Skip to content

Instantly share code, notes, and snippets.

@abovedave
Created October 18, 2013 15:51
Show Gist options
  • Save abovedave/7043573 to your computer and use it in GitHub Desktop.
Save abovedave/7043573 to your computer and use it in GitHub Desktop.
mysqldump all databases on a given host as separate .zip files
#!/usr/bin/env bash
destination="/path/to/save/sql"
mysql_host="localhost"
mysql_user="readaccount"
mysql_pass="password"
databases=`mysql -h$mysql_host --user=$mysql_user -p$mysql_pass -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema)"`
for db in $databases;
do
echo `$db`;
mysqldump --verbose --max_allowed_packet=1073741824 --opt --skip-lock-tables -h$mysql_host -u $mysql_user -p$mysql_pass $db | gzip > "$destination/$db.sql.zip"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment