Created
February 26, 2015 23:42
-
-
Save kevinelliott/4bed36a740fd82e0bd4f to your computer and use it in GitHub Desktop.
Simple bash script to drop a mysql database, create the database, and then import it using pv to display progress of the large import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# import_mysql_db - Drops the database and then imports it from sql file | |
# | |
# 2015-02-26, Kevin Elliott, kevin@catalyzed.io | |
# | |
if [ $# -ne 3 ]; | |
then | |
echo "syntax: import_mysql_db <database_user> <database_name> <sql_file>"; | |
exit 1; | |
fi; | |
database_user=$1 | |
database_name=$2 | |
sql_file=$3 | |
if [ ! -f $sql_file ]; | |
then | |
echo "File $sql_file does not exist!" | |
exit 1; | |
fi; | |
# Drop the database (it will ask to confirm) | |
mysqladmin -u$database_user drop $database_name | |
mysqladmin -u$database_user create $database_name | |
# Import the database (and use pv) | |
pv $sql_file | mysql -u$database_user $database_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment