LOAD DATA LOCAL INFILE语法错误

时间:2015-07-08 05:00:42

标签: mysql cron

使用MySQL:mysql Ver 14.14 Distrib 5.6.24,debian-linux-gnu(x86_64)使用EditLine包装器

我正在尝试将LOAD DATA LOCAL INFILE作业设置为每天运行两次。我在排序语法时非常困难。目前,我有这个:

#!/bin/bash

mysql --user=dbuser --password="dbuserpassword" --database=DSDB --local-infile --execute "

LOAD DATA LOCAL INFILE '/mnt/hqsccm/TSReport.CSV'
INTO TABLE temptable
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
(@compname,@imgdate,@imgname,@imgsttime,@imgendtime,@tottime,@engname,@engemail) set ComputerName=@compname,ImagingDate=@imgdate,ImageName=@imgname,ImageSTartTime=@imgsttime,ImageEndTime=@imgendtime,TotalTime=@tottime,EngineerName=@engname,EngineerEmail=@engemail;

TRUNCATE HQSCCMmachines;

INSERT INTO HQSCCMmachines (ComputerName,ImagingDate,ImageName,ImageSTartTime,ImageEndTime,TotalTime,EngineerName,EngineerEmail)
SELECT (ComputerName,ImagingDate,ImageName,ImageSTartTime,ImageEndTime,TotalTime,EngineerName,EngineerEmail)
  FROM temptable

TRUNCATE temptable;
"

我一直这样说:

ERROR 1064 (42000) at line 11: 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 'temptable' at line 5

帮助?

1 个答案:

答案 0 :(得分:1)

这应该有效(如果文件和表存在) -

    LOAD DATA LOCAL INFILE '/mnt/hqsccm/TSReport.CSV'
INTO TABLE temptable
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
(@compname,@imgdate,@imgname,@imgsttime,@imgendtime,@tottime,@engname,@engemail) set ComputerName=@compname,ImagingDate=@imgdate,ImageName=@imgname,ImageSTartTime=@imgsttime,ImageEndTime=@imgendtime,TotalTime=@tottime,EngineerName=@engname,EngineerEmail=@engemail;

TRUNCATE HQSCCMmachines;

INSERT INTO HQSCCMmachines (ComputerName,ImagingDate,ImageName,ImageSTartTime,ImageEndTime,TotalTime,EngineerName,EngineerEmail)
SELECT ComputerName,ImagingDate,ImageName,ImageSTartTime,ImageEndTime,TotalTime,EngineerName,EngineerEmail
  FROM temptable;

TRUNCATE temptable;