0

我正在尝试从仍在 excel 中的 csv 文件加载数据。到目前为止,这是我作为我的 sql 查询的语句:

LOAD DATA LOCAL INFILE 'C:\\Documents and Settings\\J03299\\Desktop\\TMETER.csv' 
INTO TABLE edata 
COLUMNS TERMINATED BY ',' ENCLOSED BY "" LINES TERMINATED BY '\n' 
(Year,Month,Day,MJD,xpiles,xstacks,Utilites); 

它导入第一行,然后忽略每隔一行,直到第 157 行?我想知道我缺少的是我的分隔符吗?以“\n”结尾的行?我的数据看起来像这样

2012,23,45,-0.876,3.456,768.50,

不知何故,我猜它没有读取文件的结尾

有没有其他工具可以用来导入这些信息

4

4 回答 4

2
于 2012-06-05T01:01:49.837 回答
1

解决了问题...这是我的愚蠢错误,显然我在创建表时使用年份作为主键,但年份不是唯一的。仅表示两个值,即 2012 年和 2013 年,因此它仅读取 2012 年的第一行,并且由于所有后续行都相同,因此它忽略它们直到到达 2013 年(下一个唯一主键)并将第一行带到那他们然后又放弃了。我的 LOAD 语句没有问题。感谢大家帮助我andi在创建数据库表时应该做得更好

于 2012-06-05T14:31:17.240 回答
0

On Windows, line termination is usually the carriage return character U+000d followed by the linefeed character U+000a. As the manual states:

Note

If you have generated the text file on a Windows system, you might have to use LINES TERMINATED BY '\r\n' to read the file properly, because Windows programs typically use two characters as a line terminator. Some programs, such as WordPad, might use \r as a line terminator when writing files. To read such files, use LINES TERMINATED BY '\r'.

Therefore:

LOAD DATA LOCAL INFILE 'C:\Documents and Settings\J03299\Desktop\TMETER.csv'
    INTO TABLE edata
    COLUMNS
        TERMINATED BY ','
        ENCLOSED BY ''
    LINES
        TERMINATED BY '\r\n'
    (Year, Month, Day, MJD, xpiles, xstacks, Utilites)
于 2012-06-05T01:07:30.037 回答
0

问题是您的 SQL 查询具有:

LINES TERMINATED BY '\n' 

但是您的数据以“,”(逗号)结尾。

2012,23,45,-0.876,3.456,768.50,

尝试将该行更改为:

 LINES TERMINATED BY ',\n' 

另一种选择是通过删除尾随逗号来清理输入数据。

于 2012-06-05T01:48:09.190 回答