Skip to content

Instantly share code, notes, and snippets.

@paolooo
Created September 29, 2017 01:28
Show Gist options
  • Save paolooo/53569e275a3873161a0508399fa02016 to your computer and use it in GitHub Desktop.
Save paolooo/53569e275a3873161a0508399fa02016 to your computer and use it in GitHub Desktop.
Import db tables
#!/bin/bash
################################################
# @author Nino Paolo Amarillento #
################################################
# Usage :
#
# $ ./importer-loop.sh localhost root db_name dir
################################################
[ $# -lt 3 ] && echo "Usage: $(basename $0) <DB_HOST> <DB_USER> <DB_NAME> <DIR>" && exit 1
HOST=$1
USER=$2
DB=$3
DIR=$4
[ -n "$DIR" ] || DIR=.
DIR+="/*.sql"
echo "DB password: "
read -s DB_PASS
for f in $DIR
do
echo "Importing $f table to $DB..."
mysql -u $USER -h $HOST -p$DB_PASS $DB < $f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment