数据库查询结果导出到excel

时间:2021-09-02 03:56:00   收藏:0   阅读:8

一、postgresql数据导出

将pg数据的查询结果导出到excel需要分三步:

第一步:导出到csv

\COPY (select * from * where *) to /tmp/test_data.csv CSV HEADER;

第二步:解决中文乱码

iconv -f utf-8 -t gb18030 /tmp/test_data.csv -o /tmp/test_data_gbk.csv

第三步:另存为excel

如果包含身份证号,可能存在精度丢失,选中之后单元格格式设置为文本,另存为excel即可。

二、mysql数据导出

第一步:导出到excel

mysql -hhost_name -utest_user -ppass_word -e "select * from *" db_name > /tmp/data.xls

注意??:-h -u -p后面都不能有空格,否则导出失败!!

第二步:解决中文乱码

iconv -f utf-8 -t gb18030 /tmp/data.xls -o /tmp/data_gbk.xls

 

原文:https://www.cnblogs.com/hellowhy/p/15211917.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!