我想将MySQL数据导出到csv文件,然后想下载那个csv文件。我有查询之类的。
SELECT * INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM cdr WHERE calldate >= '2015-04-01 00:00:00'
AND calldate <= '2015-04-06 00:00:00';
哪个不行。请给我一个错误。
ERROR 1064 (42000): 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 '‘\\’
LINES TERMINATED BY '\n'
答案 0 :(得分:1)
你应该逃避&#39; \&#39;像这样签名:&#39; \\&#39;,所以你的请求将是:
&#34; SELECT * INTO OUTFILE&#39; /tmp/result.csv' FIELDS终止于&#39;,&#39;选择性地包含在&#39;&#39; ESCAPED BY&#39; \\&#39;线路终止于&#39; \ n&#39;从cdr WHERE calldate&gt; =&#39; 2015-04-01 00:00:00&#39;和calldate&lt; =&#39; 2015-04-06 00:00:00&#39;&#34;;