1.excel文件处理

删除掉标题行,另存为 以逗号分隔符的CSV文件


2.文件格式处理Notepad ++

1).文件转换为UNIX格式

2).格式转换为UTF8无BOM


3.上传到数据库导入

注意事项:

1).字符集配置,操作系统字符集LANG=en_US.UTF-8

数据库字符集UTF-8


uccc_im=# \l

                                  List of databases

   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   

-----------+----------+----------+-------------+-------------+-----------------------

 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +

           |          |          |             |             | postgres=CTc/postgres

 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +

           |          |          |             |             | postgres=CTc/postgres

 import_testdb   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

(5 rows)


 import_testdb =# 

 import_testdb =# show server_encoding ;

 server_encoding 

-----------------

 UTF8

(1 row)


 import_testdb =# show client_encoding ;

 client_encoding 

-----------------

 UTF8

(1 row)


 import_testdb =# 




2).CSV导入数据库


 import_testdb =# 

 import_testdb =# COPY zh_tbl FROM '/var/lib/pgsql/zh_data_2016.01.21.csv' DELIMITER ',';


3)客户端中文显示

SCRT客户端字符集default 修改为UTF8,解决中文字符乱码问题

pgadmin 客户端直接查询无乱码显示。