简体   繁体   English

MYSQL加载简单的csv infile无法正常工作

[英]MYSQL load simple csv infile not working correctly

MAC OSX MAVRICKS MAC OSX小牛

Hello I have a very CSV file that I am attempting to use LOAD INFILE with mysql 您好,我有一个非常CSV文件,我正在尝试将LOAD INFILE与mysql一起使用

Here is what the CSV looks like.... 这是CSV的样子...

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

d,h d,h

Here is my CREATE TABLE statement: 这是我的CREATE TABLE语句:

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

Here is my LOAD INFILE statement; 这是我的LOAD INFILE语句;

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... 我尝试了loadinfile语句的变体以及为其提供了主键ID ...但是没有任何效果...

Anyone know what is going on and why loadinfile is not working for this simple CSV? 任何人都知道发生了什么,为什么loadinfile无法用于此简单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. 如果您的csv是在Windows中创建的,则可能使用'\\ r \\ n'作为行终止符。 Try LINES TERMINATED BY '\\r\\n' 尝试以LINES TERMINATED BY '\\r\\n'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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