【问题标题】:Load data local infile from CSV file where fields are not ENCLOSED从字段未封闭的 CSV 文件加载数据本地 infile
【发布时间】:2017-04-08 22:58:47
【问题描述】:

尝试使用 load data local infile 将数据从 csv 文件导入 mysql 表:

LOAD DATA LOCAL INFILE 'wentronic.csv' INTO TABLE wentronic1 fields OPTIONALLY ENCLOSED BY \"\" ignore 1 lines

csv 中的一行:

29995;LED Driver 10-24 V (DC)/12-20 W - dimmable, 3 output voltages, 3 output currents;96869;LED Driver 10-24 V (DC)/12-20 W<br>dimmable, 3 output voltages, 3 output currents;4040849299957;01;23,66;00;0;00;0;00;0;00;0;350;1;Goobay;36;85043180900;;Goobay LED Driver 10-24 V (DC)/12-20 W, Plastic bag - dimmable, 3 output voltages, 3 output currents<br>DC current source for LEDs with electronic ballast unit<br>output voltage adjustable: 10 V/12 W, 12 V/14 W, 24 V/20 W<br>Output current adjustable: 350mA, 700mA, 1000mA<br>secured in four ways: short circuit, overheat, overload, idling<br>approved for installation in furniture<br>safe electronic separation as per protection class II;CN;0;;4,5;2;43,99;;Length;110;mm;Number of outputs;2;pieces;Output, max. amperage;1000;mA;Dimmability;dimmable;;max. performance;20;W;Width;52;mm;Height;24;mm;Output, voltage;24;V (DC);Input, Voltage Range;220 - 240 (AC);V;Appliance Class;II;;;;;;;;;;;;;;;;;1;4040849299957;0;0;0;0;0;0;0;0

问题是所有字段都没有引号,并且仅导入表中的整数字段。正如你所看到的,我试图通过说字段可选地被...包围来“欺骗”mysql :-)

有什么帮助吗? :-)

【问题讨论】:

    标签: mysql csv


    【解决方案1】:

    这个怎么样?

    LOAD DATA LOCAL INFILE '/path/to/wentronic.csv' INTO TABLE wentronic1 FIELDS TERMINATED BY ';' IGNORE 1 LINES;
    

    看起来您的字段以分号结尾,如果这是真的,您不在乎字段是否被任何东西封装。

    【讨论】:

    • 完美,没错,谢谢。事实上,我首先尝试过,但我想我的语法错误 - 认为我将忽略放在字段前面:-)
    猜你喜欢
    • 2011-02-02
    • 2013-12-12
    • 2013-02-20
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    相关资源
    最近更新 更多