简体   繁体   中英

MySQL import CSV file with load data infile is missing alternate rows

I am using the below command to import data from a CSV file.

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')

The create table statement is like this:

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

and the sample data for import file is like this:

"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"

The data is getting imported, but it is importing only alternate rows.

What I am doing wrong here?

OK found the Solution. Anyone having the same problem, can find it helpful.

change the line terminated by like this, and all rows are imported correctly.

LINES TERMINATED BY '\r\n'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM