PostgreSQL導入SQL文件報錯invalid byte sequence for encoding

在導入SQL必知必會文件時報錯:invalid byte sequence for encoding “UTF8”: 0xff
SQL必知必會提供的文件是:create.txt和populate.txt,可以使用mv create.txt create.sql重命名文件
使用psql -s mydb進入單步模式,然後使用\i create.sql導入,報錯invalid byte sequence for encoding “UTF8”: 0xff

解決方法:
使用file命令查看文件編碼
file create.sql
create.sql: Little-endian UTF-16 Unicode text, with CRLF CR Line terminators
使用iconv轉換文件編碼
iconv -f UTF-16 -t UTF-8 create.sql > createutf8.sql

同樣對populate.txt進行轉碼
file populate.txt
populate.txt: ASCII text, with CRLF line terminators
使用iconv轉換文件編碼
iconv -f ASCII -t UTF-8 populate.txt > populate.sql

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章