Skip to content

Instantly share code, notes, and snippets.

@stupergenius
Created August 15, 2012 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save stupergenius/3360473 to your computer and use it in GitHub Desktop.
Save stupergenius/3360473 to your computer and use it in GitHub Desktop.
Bash script that dumps all the tables of a given database, each table to its own file.
#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage: $0 [output-path]"
exit 1
fi
TABLES=`mysql -B -N -e "select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA='$1'"`
OUT="$2"
if [ "$OUT" == "" ]; then
OUT="."
fi
if [ ! -d $OUT ]; then
echo "$OUT does not exist"
exit 1
fi
for table in $TABLES; do
echo -n "dumping $1.$table..."
mysqldump $1 $table > $OUT/$1.$table.sql
echo "done"
done
@stupergenius
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment