Skip to content

Instantly share code, notes, and snippets.

@kevinelliott
Created February 26, 2015 23:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinelliott/4bed36a740fd82e0bd4f to your computer and use it in GitHub Desktop.
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
#!/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