views:

151

answers:

1

Hi,

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?

Thanks

+1  A: 

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.

JYelton
@YJelton: Thanks, that's more or less what I figured out. However, if I remove it, the data doesn't get entered into rows, but rather crammed into a single row in a weird way. Is there some alternative to the new line?
Tom
It imports a single row if you remove only the *last* newline/CR character? Odd. You could try creating a file with a different delimiter for the lines terminated by, such as the pipe (|) character.
JYelton
That's an idea, will give it a go, thanks.
Tom