Skip to content

Instantly share code, notes, and snippets.

@pjama
Last active December 16, 2015 08:49
Show Gist options
  • Save pjama/5408537 to your computer and use it in GitHub Desktop.
Save pjama/5408537 to your computer and use it in GitHub Desktop.
Script to load test database from dump file. Command line usage: `script.sh db_name`
#!/bin/bash
DATABASE=$1
TEST_DB_FILE="test_db.tar.gz"
mysql -uroot -e "drop database if exists $DATABASE;"
mysql -uroot -e "create database $DATABASE;"
mysql -uroot -e "show databases;"
if [ ! -f $TEST_DB_FILE ]; then
echo "Error: Missing test database."
exit -1
fi
echo -e "\nLoading test database from dump..."
tar -xOzf $TEST_DB_FILE | mysql -uroot $DATABASE
mysql -uroot -e "show databases;"
echo "Complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment