Created
November 24, 2016 07:01
-
-
Save rahilwazir/92ffa35aa2f421718de7499a498cc95a to your computer and use it in GitHub Desktop.
Import list of CSV files in a directory to mysql, where each filename must be a table name
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
#!/usr/bin/env bash | |
# cd /your/directory/to/csvtables | |
for f in *.csv | |
do | |
mysqlimport --ignore-lines=1 \ | |
--fields-terminated-by=, \ | |
--fields-enclosed-by="\"" \ | |
--fields-escaped-by=\ | |
--lines-terminated-by="\r\n" \ | |
--local -u <user> \ | |
-p <database> \ | |
$f | |
echo "Done: '"$f"'" | |
echo "_____________________________________________________________________" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment