Created
April 11, 2016 08:29
-
-
Save egel/e3f22e5ca4279c219c9be3f9442f6229 to your computer and use it in GitHub Desktop.
Simple script that help you to insert multiple csv data into MySQL database table
This file contains hidden or 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/bash | |
read -r -p "Type MySQL user (root): " USER | |
if [ -z "$USER" ]; then | |
USER=root | |
fi | |
read -r -p "Type MySQL $USER password: " PASS | |
read -r -p "Type MySQL database name: " DBNAME | |
read -r -p "Type MySQL database table: " DBTABLE | |
INPUT=ietf-language-tags.csv | |
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } | |
# All columns from CSV must be defined, otherwise it concate all other to the last column | |
while IFS="," read lang langType territory revGenDate defs dftLang file | |
do | |
echo "USE $DBNAME; INSERT INTO $DBTABLE (nameNative, nameEnglish, ietfCode, langType, territory) VALUES ('', '', '$lang', '$langType', '$territory');" | |
done < $INPUT | mysql -u $USER -p$PASS; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment