【问题标题】:"load data infile" with many files带有许多文件的“加载数据文件”
【发布时间】:2014-06-12 10:18:39
【问题描述】:

我必须从许多文件中加载数据并将数据附加到 MySQL 表中。这些文件存储在同一目录中。

要从我使用的单个文件加载数据:

load data local infile 'D:\\MyDir\\file.DAT' into table catasto.dm_import fields terminated by '|' lines terminated by '\n';

现在我需要将目录D:\MyDir 中包含的每个文件附加到表dm_import 中。 我怎样才能做到这一点?我使用 MySQL Workbench 和 Python。

【问题讨论】:

    标签: mysql load-data-infile


    【解决方案1】:

    在此线程中提供一些提示:

    Is there replacement for cat on Windows

    cd D:\MyDir;
    copy /b *.DAT _all.DAT;
    load data local infile '_all.DAT' into table catasto.dm_import fields terminated by '|' lines terminated by '\n';
    del _all.DAT;
    

    这应该让你得到你所追求的,而不需要任何 python。

    copy /b 所做的实际上是获取目录中的所有文件,将它们首尾相连,然后将输出保存在 _all.DAT

    完成后删除 _all.DAT 是个好主意,否则您可能会遇到这样的情况:除了目录……乱七八糟!

    【讨论】:

      【解决方案2】:

      首先尝试将您的文件合并到一个文件中。执行加载数据命令。您可以使用 windows 命令 copy /b *.dat newfile 然后加载数据本地 infile newfile。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-03
        • 2018-06-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多