I am looking for help to load a .csv file into MySQL Server using batch and I have few basic questions.
Issues:
1) The CSV file data may have , (comma) in between (Ex: description), so how can I make import handling these data?
2) To load CSV from Excel then the data that have comma are enclosed within "" (double quotes) [as the below example] so how do the import can handle this?
Here is the sample CSV with header:
name,id,Subject,ExamDate,Mark,Description
Prabhat,1,Math,2/10/2013,25,Test data for prabhat.
Murari,2,Science,2/11/2013,24,"Test data for his's test, where we can test 2nd ROW, Test."
sanjay,3,Science,,25,Test Only.
The SQL statement used to import:
load data local infile "c:\\eqa\\project\\input.csv" into table request character set latin1 fields terminated by',' lines terminated by'\n' ignore 1 lines
How can I do this, is it possible?
Best Answer
Since you are using
load data local infile
and Loading Data into a Table using MySQL, there is a simple solution which is provided as part of this functionality which will help you to resolve this issue.You simply want to be sure to include the
ENCLOSED BY '"'
subclause as part of theFIELD
clause in the MySQL syntax you are using— below is an example of this.This tells MySQL the input file has field values that are both enclosed by double quotes and separated by commas—All characters between double quotes will then be imported.
Further Resources