Skip to content

Instantly share code, notes, and snippets.

@cjthompson
Forked from stupergenius/MySQL Dump Tables
Last active December 15, 2015 17:20
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 cjthompson/5295937 to your computer and use it in GitHub Desktop.
Save cjthompson/5295937 to your computer and use it in GitHub Desktop.
#!/bin/bash
USER="user"
PASSWORD="password"
HOST="localhost"
MYSQL_OPTS="--compact --single-transaction --skip-opt --quick --no-create-info --skip-triggers"
if [ "$1" == "" ]; then
echo "Usage: $0 database-name [output-dir]"
exit 1
fi
TABLES=`mysql -u $USER -p$PASSWORD -h $HOST -B -N -e "select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA='$1'"`
OUT="$2"
if [ "$OUT" == "" ]; then
OUT="./sql"
fi
if [ ! -d $OUT ]; then
echo "$OUT does not exist"
exit 1
fi
if [ ! -d $OUT/$1 ]; then
mkdir $OUT/$1
fi
for table in $TABLES; do
echo -n "dumping $1.$table..."
mysqldump --user=$USER --password=$PASSWORD --host=$USER $MYSQL_OPTS $1 $table > $OUT/$1/table.sql
echo "done"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment