ubuntu 修改mysql编码为utf8
ubuntu使用apt-get安装mysql后,server的默认编码是latin1,下面把server的编码修改成utf8。
查看mysql和编码的信息
看下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的编码
打开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/ | +--------------------------+----------------------------+
完成。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。