Tom
Tom

Reputation: 30698

Blank row in table after LOAD DATA INFILE

I'm uploading a large amount of data from a CSV (I'm doing it via MySQL Workbench):

LOAD DATA INFILE 'C:/development/mydoc.csv' INTO TABLE mydatabase.mytable CHARACTER SET utf8
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r';

However, I'm noticing that it keeps adding an empty line full of nulls/zeros after the last record. I'm guessing it's because of the "LINES TERMINATED" command. However, I need that to load the data in correctly.

Is there some way around this / some better SQL to avoid the blank row in the table?

Upvotes: 2

Views: 5046

Answers (1)

JYelton
JYelton

Reputation: 36512

If you have a newline/CR character at the END of the last line, the load command will try to load another record. But because there is no data after the last newline/CR, all columns are null.

Upvotes: 3

Related Questions