简体   繁体   中英

MYSQL load simple csv infile not working correctly

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?

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM