phpMyAdmin SQL错误FIELDS附近无法识别的关键字

时间:2016-11-10 11:00:50

标签: mysql csv select-into-outfile

我正在尝试执行此MySQL以将一些数据导入到csv文件中。

SELECT *
FROM purchase WHERE purchase.PO_DATE >= '1-1-2016'
INTO OUTFILE "D:\\Reports\\Jan.csv"
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

但是我收到了输出

Static analysis:

11 errors were found during analysis.

    Unrecognized keyword. (near "FIELDS" at position 99)
    Unrecognized keyword. (near "TERMINATED" at position 106)
    Unrecognized keyword. (near "BY" at position 117)
    Unexpected token. (near "','" at position 120)
    Unrecognized keyword. (near "ENCLOSED" at position 125)
    Unrecognized keyword. (near "BY" at position 134)
    Unexpected token. (near "'"'" at position 137)
    Unrecognized keyword. (near "LINES" at position 142)
    Unrecognized keyword. (near "TERMINATED" at position 148)
    Unrecognized keyword. (near "BY" at position 159)
    Unexpected token. (near "'\n'" at position 162)

SQL query: Documentation

SELECT * FROM purchase WHERE purchase.PO_DATE >= '1-1-2016' INTO OUTFILE "D:\\Reports\\Jan.csv" FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' 

任何人都知道如何解决这个问题?

2 个答案:

答案 0 :(得分:4)

有关输出文件的信息应在SELECTFROM条款之间指定:

SELECT *
INTO OUTFILE "D:\Reports\Jan.csv"
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'    
FROM purchase 
WHERE purchase.PO_DATE >= '1-1-2016'

MySQL 5.7 Reference Manual | LOAD DATA INFILE Syntax

答案 1 :(得分:1)

from子句处于错误的位置 应该是

SELECT * 
INTO OUTFILE "D:\Reports\Jan.csv"
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM purchase 
WHERE purchase.PO_DATE >= '1-1-2016'