在導入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