1

I am trying to upload a csv to a MySql database but the following code is not working. I am entering the query directly into MySql.

Create table testing.test (
test VARCHAR(50),
test2 VARCHAR(50),
primary key (test));

LOAD DATA LOCAL INFILE 'C:/test.csv' 
             INTO TABLE testing.test
             FIELDS 
                TERMINATED BY ','
             LINES TERMINATED BY '\r\n';

Basically it deletes all rows but the final row of the table. It produces the following message: "7 row(s) affected Records: 8 deleted: 0 Skipped". Any ideas why the rows are being deleted?

2
  • 3
    I would assume that your line break encoding does not match that of the csv file. Commented Jun 5, 2017 at 18:35
  • yup, it should be '\n'. Thanks! Commented Jun 5, 2017 at 18:42

1 Answer 1

1

Posting my comment to the question as answer for others:

I would assume that your line break encoding does not match that of the csv file. That can result in lines getting skipped, since they do not match the described format. Only the last line will get accepted in such scenario, since for that no terminating line break is required.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.