mysql错误“无法识别的语句类型。(终止于附近)”

时间:2018-12-04 13:27:45

标签: mysql import load

我有mysql版本5.7.19 我正在尝试运行此

load data infile 'C:\projects\v1.csv' into table ups terminated by ',' lines terminated by '\n' (company,ups_name,ups_ip,ups_mac,community,type_id,mdm_mac,ter_dir,td,cty,city,location,address,is_active,connected_device_name,connected_device_type,on_id,optical_node,inserted,updated);

但是出现错误:

unrecognized statement type. (near terminated by)

#1064 - You have an error in your SQL syntax; check 
the manual that corresponds to your MySQL server version 
for the right syntax to use near 'terminated by ','
lines terminated by '\n' (company,ups_name,ups_ip,ups_mac,comm' at line 1

我检查了语法是否正确。 我不知道怎么了? 谢谢

1 个答案:

答案 0 :(得分:0)

如果您阅读the documentation very closely,则可以看到FIELDS是可选的,如果您承诺使用该选项,则必须包括该部分:

LOAD DATA INFILE 'C:\projects\v1.csv' INTO TABLE ups
  FIELDS TERMINATED BY ','
  LINES TERMINATED BY '\n'
    (company,ups_name,ups_ip,ups_mac,community,type_id,mdm_mac,ter_dir,td,cty,city,location,address,is_active,connected_device_name,connected_device_type,on_id,optical_node,inserted,updated);

FIELDSLINES都不会终止,因为它们都有一个TERMINATED BY组件。

具体地说,{FIELDS | COLUMNS}表示 之一,而不是可选的。