Ubutun使用记录——语系错误(转)
add by zhj: 对原文有修改,原文是在创建用户时出现的问题,而我是在使用psql时出现的,
但问题是相同的。
原文:http://www.douban.com/note/362250557/
SSH远程连接到Ubutun,用psql时出错
ajian@ubuntu:~$ psql
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US:en",
LC_ALL = (unset),
LC_PAPER = "zh_CN.UTF-8",
LC_ADDRESS = "zh_CN.UTF-8",
LC_MONETARY = "zh_CN.UTF-8",
LC_NUMERIC = "zh_CN.UTF-8",
LC_TELEPHONE = "zh_CN.UTF-8",
LC_IDENTIFICATION = "zh_CN.UTF-8",
LC_MEASUREMENT = "zh_CN.UTF-8",
LC_TIME = "zh_CN.UTF-8",
LC_NAME = "zh_CN.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
psql (9.1.13)
Type "help" for help.
ajian=>
虽然也能连接到数据库,但查询时中文无法正常显示
在Stack Overflow中发现如下帖子:
http://stackoverflow.com/questions/2499794/how-can-i-fix-a-locale-warning-from-perl。
发现是SSH连接时,远程主机的/etc/ssh/sshd_config的文件有如下设置:
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
远端会读取SSH客户端的语系配置,但远端支持语系里没有SSH客户端的当前语系,所以出现上述错误。
从上面的打印可以看到,SSH客户端语系中使用了en_US:en,zh_CN.UTF-8,en_US.UTF-8,我们
看一下远端,如下
远端支持语系
root@LePlanet:~# locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX
所以,远端需下载 zh_CN.UTF-8
root@LePlanet:~# sudo locale-gen zh_CN.UTF-8
Generating locales...
zh_CN.UTF-8... done
Generation complete.
再查看:
root@LePlanet:~# locale -a
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX
zh_CN.utf8
这样就可以了。此外,可以用sudo locale-gen,更新语系至最新。