带有加载数据infile的MySQL导入CSV文件缺少备用行

时间:2015-04-21 17:45:58

标签: mysql csv

我使用以下命令从CSV文件导入数据。

load data infile  'l:\health_card.csv'
into table health_card
fields terminated by ','
enclosed by '"'
LINES TERMINATED BY '\n'
ignore 1 lines
( @date,  health_card_number, patient_name,age,street_address,mobile,@birth_date,@anniversary,card_rate,card_amount,relation_name)
set date = STR_TO_DATE(@date, '%m.%d.%Y'),
birth_date = STR_TO_DATE(@birth_date, '%m.%d.%Y'),
anniversary = STR_TO_DATE(@anniversary, '%m.%d.%Y')

create table语句是这样的:

CREATE TABLE `health_card` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `health_card_number` varchar(30) DEFAULT NULL,
 `patient_name` varchar(50) DEFAULT NULL,
 `general_regn_number` varchar(30) DEFAULT NULL,
 `date` date DEFAULT NULL,
 `relation_name` varchar(300) DEFAULT NULL,
 `relation` varchar(30) DEFAULT NULL,
 `age` int(11) DEFAULT NULL,
 `birth_date` date DEFAULT NULL,
 `anniversary` date DEFAULT NULL,
 `address_relation` varchar(256) DEFAULT NULL,
 `street_address` varchar(50) DEFAULT NULL,
 `village` varchar(50) DEFAULT NULL,
 `city` varchar(30) DEFAULT NULL,
 `state` varchar(30) DEFAULT NULL,
 `pincode` mediumint(9) DEFAULT NULL,
 `email` varchar(50) DEFAULT NULL,
 `mobile` varchar(15) DEFAULT NULL,
 `card_rate` decimal(10,0) DEFAULT NULL,
 `card_amount` decimal(10,0) DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `patient_name` (`patient_name`)
) ENGINE=InnoDB AUTO_INCREMENT=513 DEFAULT CHARSET=utf8

,导入文件的示例数据如下:

"date","health_card_number","patient_name","age","street_address","mobile","birth_date","anniversary","card_rate","card_amount","relation_name"
"28.10.14","2821","Shyamsundar Agrawal","63","Khetrajpur, SBP","9438625411","","","100","100","W- Kantabai , S- Amit, D/L- Vinata, G/S- Harsh, G/D- Khusi"
"28.10.14","2822","Bisakha Kharsel","62","Fasimal, SBP","9777310693","05.01.1952","08.03.1970","100","100","H- Gulbadan, S-Bipra, D/L- Sulochana, G/S- Rajkumar, G/D-Jhili"
"29.10.14","2823","Upendra Prasad Gupta","39","Baraipali,SBP","9861358110","04.01.1973","","100","100","W- Reena Devi, F- Hira Prasad Gupta, M- Shanti Devi, B- Rajendra, B- Mukesh"
"29.10.14","2824","Kamaljit Singh","34","Baraipali, SBP","9861018383","04.08.1980","07.02.2000","100","100","W- Navneet KAUR, F- Sikandar Singh, M-Kuldeep, S- Jaspreet, D-Gurpreet"

数据已导入,但仅导入备用行。

我在这里做错了什么?

1 个答案:

答案 0 :(得分:7)

确定找到了解决方案。任何有同样问题的人都会觉得有帮助。

更改以此方式终止的行,并正确导入所有行。

LINES TERMINATED BY '\r\n'