Skip to content

Instantly share code, notes, and snippets.

@knzm
Last active August 22, 2020 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knzm/ca0088fc1b16f7c54f56c88ae5f6ca83 to your computer and use it in GitHub Desktop.
Save knzm/ca0088fc1b16f7c54f56c88ae5f6ca83 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -eu
SELECT_SCHEMA_SQL=<<EOF
SELECT SCHEMA_NAME FROM information_schema.SCHEMATA
WHERE SCHEMA_NAME NOT IN ("information_schema", "performance_schema");
EOF
mysql -u root -N -e "${SELECT_SCHEMA_SQL}" | while read dbname; do
echo "Dumping database $dbname"
time mysqldump -u root --single-transaction --databases $dbname | gzip -c >| "${dbname}.sql.gz";
echo "Done."
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment