0

MAC OSX MAVRICKS

Hello I have a very CSV file that I am attempting to use LOAD INFILE with mysql

Here is what the CSV looks like....

f1,f2
a,e
b,f
c,g 

d,h

Here is my CREATE TABLE statement:

create table test_import_csv (
f1 VARCHAR(20), 
f2 VARCHAR(20)
);

Here is my LOAD INFILE statement;

load data local infile '/Users/name/Downloads/test_import_csv.csv' 
into table test_import_csv
fields terminated by ','
LINES TERMINATED BY '/n'
(f1, f2);

this statement goes through however this is what it looks like...

mysql> select * from test_import_csv;
+------+------+
| f1   | f2   |
+------+------+
a |1   | f2
+------+------+
1 row in set (0.00 sec)

I have tried variations in the loadinfile statement as well as giving it an primary KEY ID... but nothing works...

Anyone know what is going on and why loadinfile is not working for this simple CSV?

2
  • 2
    You should use LINES TERMINATED BY '\n' Commented Nov 20, 2013 at 23:56
  • replaced that here is what happened output still is wrong, its only importing one row and not even the first one weird... mysql> select * from test_import_csv; +------+------+ | f1 | f2 | +------+------+ b | | e +------+------+ 1 row in set (0.00 sec) Commented Nov 21, 2013 at 0:31

1 Answer 1

2

If your query can import one row, I suspect the problem is with your line termination. If your csv is created in Windows it may be using '\r\n' as line terminator. Try LINES TERMINATED BY '\r\n'

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

2 Comments

you were right as soon as I did that it worked..... Every single place I looked either said '\r' or '\n' or '\rb' but never both r and n. Probably one of the most frustrating things ever
spend all the internet and conclude this => THIS WORKS.

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.