Created
September 24, 2019 21:45
-
-
Save jakub-roman/7de8e9725c30ee6b86ca7c78bfc8c3f4 to your computer and use it in GitHub Desktop.
This file contains 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 | |
CESTA_K_CSV="/tmp/CSV" ## cesta, kde jsi rozbalil archiv (cesta až k souborům) | |
###################### | |
USER="root" ## uživatel do DB | |
PASSWORD="" ## heslo do DB | |
DB="adresy" ## databáze | |
TABLE="adresni_mista" ## tabulka v DB, kam se budou importovat data | |
###################### | |
set -eu | |
# all files | |
files=$(ls $CESTA_K_CSV) | |
TMP_DIR=$(mktemp -d) | |
# fix all encodings | |
echo Re-code files to utf-8 | |
for f in $files | |
do | |
iconv -f cp1250 -t utf-8 ${CESTA_K_CSV}/${f} > ${TMP_DIR}/${f} | |
done | |
# import | |
echo Import into mysql | |
for f in $files; do | |
mysql -u $USER -p $PASSWORD --local_infile=1 $DB -e "LOAD DATA LOCAL INFILE '${TMP_DIR}/${f}' INTO TABLE $TABLE FIELDS TERMINATED BY ';' IGNORE 1 ROWS" | |
done | |
rm -r ${TMP_DIR} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment