2013. 1. 28.

import csv into mysql by load data (skip some column)

It's very general , well known topic.but when we need time to find and use it.
I blogged it to remember. 




load data infile 'aa.csv' into table tbl_name
character set 'UTF8'
fields terminated by ','  optionally enclosed by '"' escaped by '\\'
lines terminated by '\r\n'  starting by ''
ignore 1 lines

 (col1, col2, col3
;


case 2: when number of column of table and csv data
  1- when you want drop some column of csv.  ( drop v4, v5)
     ex) csv contents : v1, v2, v3, v4, v5

 load data infile 'aa.csv' into table tbl_name
character set 'UTF8'
fields terminated by ','  optionally enclosed by '"' escaped by '\\'
lines terminated by '\r\n'  starting by ''
ignore 1 lines

 (col1, col2, col3, @dummy1, @dummy2)   -- @dummy just read and drop




Enhanced by Zemanta