Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active August 29, 2015 14:11
Show Gist options
  • Save mrded/bc5be9a4420f1fece6b4 to your computer and use it in GitHub Desktop.
Save mrded/bc5be9a4420f1fece6b4 to your computer and use it in GitHub Desktop.
mysql: Import database with truncated tables.
#!/bin/bash
# Usage:
# $ bash import-dump.sh http://example.co.uk/dump.sql.gz
start=$(date +"%s")
echo "-> Deleting of old tables"
mysql --user=root -e 'DROP DATABASE wikijob;'
mysql --user=root -e 'CREATE DATABASE wikijob;'
echo "-> Downloading and importing of new tables"
curl -H 'Accept-encoding:gzip' $1 | gunzip -c | grep -v 'INSERT INTO `user_relationship_locator_facebook`'| mysql --user=root wikijob
end=$(date +"%s")
diff=$(($end-$start))
echo "Time spent: $(($diff / 60))m$(($diff % 60))s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment