Skip to content

Instantly share code, notes, and snippets.

@rahilwazir
Created November 24, 2016 07:01
Show Gist options
  • Save rahilwazir/92ffa35aa2f421718de7499a498cc95a to your computer and use it in GitHub Desktop.
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
#!/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