我有一个csv文件,其中包含双引号内的一些字段,因为它们中包含逗号。样本数据:
ID, NAME, ADDRESS
1, Tom Jones, "Home, 123 Ave, TX"
2, John Thomas, "Office, 321 St TX"
我尝试按照here的步骤操作,使用OPTIONALLY ENCLOSED BY '"'
将数据加载到我的数据库但我一直在
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 'OPTIONALLY ENCLOSED BY '"'' at line 1
我的加载命令如下:
LOAD DATA INFILE
'C:\Users\Craig\Downloads\de1\Data\contacts.csv'
INTO TABLE TEST1.contacts
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
;
我在这里做错了什么?
答案 0 :(得分:0)
我在navicat和cmd.exe中都尝试过SQL。我在cmd.exe上遇到与您相同的错误,但在navicat上运行良好。键是SQL中文件路径上的符号“”。您应将反斜杠替换为斜杠。 就是这样:
LOAD DATA INFILE
'C:/Users/Craig/Downloads/de1/Data/contacts.csv'
INTO TABLE TEST1.contacts
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
;