0

Trying to load a .csv this simple:

"Id";"Values"
"1";"Value1"
"2";"Value2"
...
...
"n";"Valuen"

Into a table with 2 fields

id       int(11) primary
values   varchar(255)

like this:

LOAD DATA LOCAL INFILE 'file_name.csv'
REPLACE
INTO TABLE tbl_name
FIELDS
    TERMINATED BY ';'
    ENCLOSED BY '"'

LINES TERMINATED BY '\n'
IGNORE 1 LINES

but when i load it, I get something like

+----+--------------+
| id | value        | 
+----+--------------+
|  1 | value1" "2   | 
|  2 | value3" "4   |
|  3 | value5" "6   |
|  4 | value7" "8   |
|  5 | value9" "10  | 
|  6 | value11" "12 | 
+----+--------------+

as if it didn't understand the linebreak rule \n

pulling my hair off already. what am I doind wrong?

in other words, what is the correct query for loading this file?

2
  • Do you have access to a hex editor? Make sure that the line break is just \n and there aren't some other non-printable characters in there. Commented Feb 23, 2014 at 14:16
  • @Michael Berkowski thanks for the hex editor tip! Commented Feb 23, 2014 at 14:25

1 Answer 1

1

Try below one-

LOAD DATA LOCAL INFILE 'file_name.csv' REPLACE INTO TABLE tbl_name FIELDS ESCAPED BY '\\' TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;
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.