1. 程式人生 > >阿里雲新機器關於中文亂碼的坑

阿里雲新機器關於中文亂碼的坑

首先更改centos系統中文亂碼


locale -a 檢視已經安裝的語言包

沒有的話用 yum install kde-l10n-Chinese 安裝

修改 vim /etc/sysconfig/i18n

LANG="zh_CN.UTF-8"
LC_ALL="zh_CN.UTF-8"

#  source    /etc/sysconfig/i18n

再修改 locale.cnf配置檔案
#   vim /etc/locale.conf

LANG="zh_CN.UTF-8"

#  source   /etc/locale.conf
重啟系統
# reboot

warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such
file or directory

在/etc/environment加入(沒有就新建):

LC_ALL=zh_CN.UTF-8
LANG=zh_CN.UTF-8

mysql中文亂碼

mysql> show variables like 'character_set%';
+--------------------------+----------------------------+ 
| Variable_name | Value | 
+--------------------------+----------------------------+ 
| character_set_client | latin1 | 
| character_set_connection | latin1 | 
| character_set_database | latin1 | 
| character_set_filesystem | binary | 
| character_set_results | latin1 | 
| character_set_server | latin1 | 
| character_set_system | utf8 | 
| character_sets_dir | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+ 

修改
vim /etc/my.cnf

[mysqld]
character-set-server=utf8