Home >Database >Mysql Tutorial >mysql 导出数据为cvs

mysql 导出数据为cvs

WBOY
WBOYOriginal
2016-06-07 16:33:251065browse

写了一个Shell脚本,导出一段时间的数据到 cvs: fileName="data"`date --date=$date "+%Y%m%d"`".csv";#mysql里先导出数据到 xml, 用 select into outfile 导出, 设定字段分隔符和记录分隔符/usr/local/webserver/mysql/bin/mysql -h "$mysql_host" -u "$m

写了一个Shell脚本,导出一段时间的数据到 cvs:

fileName="data"`date --date=$date "+%Y%m%d"`".csv";
#mysql里先导出数据到 xml, 用 select into outfile 导出, 设定字段分隔符和记录分隔符
/usr/local/webserver/mysql/bin/mysql -h "$mysql_host" -u "$mysql_username" --password="$mysql_password"  -e "select *  INTO OUTFILE '$data_dir$fileName' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'  LINES TERMINATED BY '\\n'  from $table where InTime>=$minTime && InTime  $final_dir$fileName

先用select into outfile 把数据从mysql 里边倒出来,其中字段分隔符 \t , 记录分隔符为 \n, 然后转一下字符的编码就OK了!!

声明: 本文采用 CC BY-NC-SA 3.0 协议进行授权

转载请注明来源:小景的博客

本文链接地址:http://www.phpv5.com/blog/archives/475/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn