如何使用mysql查询导出表数据?

时间:2015-01-09 12:26:28

标签: php mysql sql csv

SELECT * FROM `tbProgramDetls`
WHERE dPrgrmdate
BETWEEN "2015-01-01"
AND "2015-01-08"
INTO OUTFILE 'directory' -> C:\myTable.csv
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

显示错误: -

  

1064 - 您的SQL语法出错;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近' - > C:\ myTable.csv FIELDS终止于','包含在'"' LINES   TERMINATE'在第5行

如何执行此查询。

1 个答案:

答案 0 :(得分:2)

您的语法应为:

SELECT * FROM `tbProgramDetls`
WHERE dPrgrmdate
BETWEEN "2015-01-01"
AND "2015-01-08"
INTO OUTFILE 'C:\myTable.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'; 

根据手册 http://dev.mysql.com/doc/refman/5.1/en/select-into.html

的示例
SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY '\n'
  FROM test_table;