我需要从 mysql 服务器获取数据并导出到 .csv 文件。我需要每天自动将数据导出到新的 .csv 文件。
查询:select count(*) count,create_date from tabpush where status=1 and create_date between '2015-12-05' AND '2015-12-06' order by create_date desc ;
我怎么做 ?
环境:
操作系统:centos6.6
答案1
您可以使用 MySQL 的 select ... into outfile 轻松实现此目的。例如这样:
select count(*) count,create_date from tabpush
where status=1 and create_date between subdate(current_date, 1) AND current_date()
order by create_date desc
INTO OUTFILE '/tmp/daily.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';