Skip to content

Instantly share code, notes, and snippets.

@pstaender
Created March 28, 2015 12:45
Show Gist options
  • Save pstaender/18c4aaf25461554329b9 to your computer and use it in GitHub Desktop.
Save pstaender/18c4aaf25461554329b9 to your computer and use it in GitHub Desktop.
Import MySQL Dumps (batch)
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No arguments supplied"
exit 1
fi
SOURCEDIR="$1"
if [ ! -d "$SOURCEDIR" ]; then
echo "$SOURCEDIR does not exists / or is not a dir"
exit 1
fi
# unzip gzipped sql files
ls $SOURCEDIR | while read FILE; do
NAME=$(echo $FILE | sed -e "s/-201.*$//")
echo "importing $FILE to database $NAME; drop and recreate database;"
echo "drop database if exists $NAME; create database $NAME;" | mysql
# unzip / extract sql dump and import to mysql
gunzip < $SOURCEDIR/$FILE | mysql --database $NAME
done
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment