在包含加载数据文件的字段中以逗号导入CSV

时间:2018-07-18 06:42:52

标签: mysql csv load-data-infile

我有一个CSV文件,格式如下:

nconst,primaryName,birthYear,deathYear,primaryProfession,knownForTitles
nm0000001,Fred,1899,1987,"soundtrack,actor,miscellaneous","tt0072308,tt0045537"
nm0000002,Lauren,1924,2014,"actress,soundtrack","tt0038355,tt0117057,tt0037382"

有些字段用引号("")括起来,这不是问题,并且字段以逗号(,)作为分隔符。

我正在mysql命令行中使用以下命令:

load data local infile '/home/ec2-user/sample.csv' into table movies.`sample` fields terminated by ',' enclosed by '"' lines terminated by '\n' ignore 1 lines; 

哪个实习生没有错误,但是数据以以下错误格式插入表中:

**nm0000001**   Fred  1899  1987    soundtrack,actor,miscellaneous  tt0043044,tt0072308,tt0050419,tt0045537" **nm0000002**,Lauren Bacall,1924,2014,"actress,soundtrack

我们可以清楚地看到,第二行的数据会追加到第一行

预先感谢

编辑

表定义:

 CREATE TABLE `sample` (
   `nconst` text,
   `primaryName` text,
   `birthYear` int(11) DEFAULT NULL,
   `deathYear` text,
   `primaryProfession` text,
   `knownForTitles` text
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

0 个答案:

没有答案