mysql: import csv data

by prettyscripts on 2011-12-16 10:47

sql

there are a few ways to to it. here's a solution using load data.

Code:

load data local infile '/path/to/csvfile'
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
[ignore 1 lines]
[(column_1, @dummy, column_2,...)]

notes

line 5: this will ignore the 1st line in csv file if that's a header row.

line 6: specify the column name if the column order in table is different from the order in csv file. specify @dummy if to skip data in csv file.