數據庫查詢結果導出到excel


一、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即可。

 

二、pg導出數據庫中的表結構

pg_dump -h 127.0.0.1  -p 5432 -U userName --column-inserts db_name> /tml/db_name.sql

 

三、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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM