2011-08-15 74 views
1

我有問題與MySQL的LOAD DATA命令。MySQL負載數據與多行數據

使用簡單的數據,它工作正常。

當我嘗試加載數據很長,並且有一個字段延伸到很多行時,它會失敗。

這是我的輸入數據。字段以製表符分隔。

1 2008-06-27 12:00:00 Type-Safe Enumerations title Fr 5 
...line 1.. 
...line 2.... 
    \N 2002-10-01 12:00:00 END-OF-THE-LINE 
2 2008-06-27 12:00:00 Class for constants Classe pour constantes 1 
line 1... 
..line 2.. 
    \N 2002-10-01 12:00:00 END-OF-THE-LINE 
4 2008-06-27 12:00:00 Another Énumérations 5 
line 1 
line 2 
    \N 2002-10-01 12:00:00 END-OF-THE-LINE 
5 2008-06-27 12:00:00 And Another Énumérations 5 
line 1 
line 2 
    \N 2002-10-01 12:00:00 END-OF-THE-LINE 

而這裏的LOAD DATA命令:

>LOAD DATA LOCAL INFILE "TopicInfileText2.dat" INTO TABLE Topic 
    LINES TERMINATED BY "END-OF-THE-LINE"; 

目標表:從MySQL

| Incorrect integer value: ' 
2' for column 'Id' at row 2 | 
| Incorrect integer value: ' 
4' for column 'Id' at row 3 | 
| Warning | 1366 | Incorrect integer value: ' 
5' for column 'Id' at row 4 | 
| Warning | 1366 | Incorrect integer value: ' 
' for column 'Id' at row 5 | 

回答

2

CREATE TABLE Topic ( 
    Id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, 
    LastEdit TIMESTAMP NOT NULL,    
    TitleEnglish VARCHAR(75) NOT NULL, 
    TitleFrench VARCHAR(75), 
    ChapterId SMALLINT NOT NULL References Chapter,    
    BodyEnglish TEXT NOT NULL,    
    BodyFrench TEXT,    
    CreationDate DATETIME NOT NULL, 
    PRIMARY KEY (Id) 
); 

警告錯誤是在LOAD DATA命令。我錯過了一個換行符。

本來應該是:

LOAD DATA LOCAL INFILE "TopicInfileText2.dat" INTO TABLE 
    Topic LINES TERMINATED BY "END-OF-THE-LINE\n";