我正在开发一个需要使用 Workbench 将 csv 数据导入 mysql 表的项目。我尝试运行以下命令。我没有收到任何错误,但是没有记录被导入到表中。请注意,我尝试更改以 to 结尾的行\n
,也尝试\r
了,这导致了相同的结果。
我很感激有关如何解决的任何建议。
这是我尝试过的查询:
LOAD DATA LOCAL INFILE 'data-to-import.csv' INTO TABLE db.t1
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(id,age,spns,pns,spns2,sns,ps,ss,gid,term,band)
数据导入.csv
,18,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,19,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,20,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,21,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,22,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,23,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,24,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,25,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,26,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,27,0.455,0.62,0.774,1.083,2.408,3.702,1,10,1
,28,0.455,0.62,0.774,1.088,2.416,3.702,1,10,1
,29,0.455,0.62,0.792,1.121,2.489,3.702,1,10,1
db.t1 定义
CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`age` int(11) NOT NULL,
`spns` decimal(4,4) NOT NULL,
`pns` decimal(4,4) NOT NULL,
`spns2` decimal(4,4) NOT NULL,
`sns` decimal(4,4) NOT NULL,
`ps` decimal(4,4) NOT NULL,
`ss` decimal(4,4) NOT NULL,
`gid` int(11) NOT NULL,
`term` int(11) DEFAULT NULL,
`band` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;