MySQL LOAD DATA 具有多行数据

发布于 2024-11-30 02:09:12 字数 1569 浏览 2 评论 0原文

我在使用 Mysql 的 LOAD DATA 命令时遇到问题。

使用简单的数据,它就可以正常工作。

当我尝试加载很长并且有一个跨越多行的字段的数据时,它会失败。

这是我的输入数据。字段以制表符分隔。

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";

目标表:

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)
);

来自 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  |

I'm having problems with Mysql's LOAD DATA command.

With simple data, it works fine.

When I try to load in data which is long, and has a field which extends over many lines, it fails.

Here's my input data. Fields are tab-delimited.

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

And here's the LOAD DATA command:

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

The target table :

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)
);

Warnings from 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  |

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡尘雨 2024-12-07 02:09:12

错误出现在 LOAD DATA 命令中。我缺少一个换行符。

应该是:

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

The error was in the LOAD DATA command. I was missing a newline character.

Should have been:

LOAD DATA LOCAL INFILE "TopicInfileText2.dat" INTO TABLE 
    Topic LINES TERMINATED BY "END-OF-THE-LINE\n";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文