使用Mysql的LOAD DATA出错

时间:2014-10-30 15:12:04

标签: mysql csv load-data-infile

我在尝试从csv在mysql数据库中插入数据时遇到问题。我的脚本如下:

    LOAD DATA LOCAL INFILE '/home/michael/Documents/Data/converted_sourceA/EURUSD_MyData_60_20140801_20140831.csv'  
INTO TABLE DATA_OHLCV  
FIELDS TERMINATED BY ';'
ENCLOSED BY '"'  
LINES TERMINATED BY '\n' 
(@var1, open, high, low, close, volume)  
set date = STR_TO_DATE(@var1, '%Y%m%d-%H%i%s.%f'),
set id_source = 'srcA',
set timeframe = 60,
set id_asset = 'EURUSD';

错误消息是:

错误1064(42000):您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以便在#set; set id_source =' srcA'附近使用正确的语法, 设定时间= 60, 设置id_asset =' EURUSD''第8行

我真的没有看到我的错误,而且我一直在寻找它。 有人能帮助我吗?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

你有太多SET,你只需要把它放一次然后用逗号分隔字段:

LOAD DATA LOCAL INFILE '/home/michael/Documents/Data/converted_sourceA/EURUSD_MyData_60_20140801_20140831.csv'  
INTO TABLE DATA_OHLCV  
FIELDS TERMINATED BY ';'
ENCLOSED BY '"'  
LINES TERMINATED BY '\n' 
(@var1, open, high, low, close, volume)  
set date = STR_TO_DATE(@var1, '%Y%m%d-%H%i%s.%f'),
id_source = 'srcA',
 timeframe = 60,
id_asset = 'EURUSD';