Skip to content

Instantly share code, notes, and snippets.

@kurozumi

kurozumi/insert_csv.sh

Last active Oct 7, 2015
Embed
What would you like to do?
【シェルスクリプト】CSVファイルを読み込んでMySQLでデータベースに保存
#!/bin/sh
CSVFILE="filename.csv"
# passwordは先頭に-pを付ける
MYSQL="mysql -vvv -u username -ppassword database"
while read LINE
do
COL1=$(echo $LINE | cut -d "," -f 1)
$MYSQL <<EOF
INSERT INTO table_name (col_name1) VALUES ('$COL1');
EOF
done < $CSVFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.