标签:
ubuntu使用apt-get安装mysql后,server的默认编码是latin1,下面把server的编码修改成utf8。
看下mysql的信息:
mysql> select version(); +-------------------------+ | version() | +-------------------------+ | 5.5.41-0ubuntu0.14.04.1 | +-------------------------+
编码相关信息:
mysql> show variables like ‘character%‘; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+
可以看到character_set_database 和 character_set_server 的编码都是latin1。
打开mysql的配置文件/etc/mysql/my.cnf
vim /etc/mysql/my.cnf
在[mysql]里追加
default-character-set=utf8
保存后,重启mysql。
/etc/init.d/mysql restart
编码就正确了。
mysql> show variables like ‘character%‘; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+
完成。
标签:
原文地址:http://my.oschina.net/mxs/blog/395580