mysql设置字符集CHARACTER SET
Posted Neither Candidate
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql设置字符集CHARACTER SET相关的知识,希望对你有一定的参考价值。
在 my.cnf 配置文件中设置相关选项,改变为相应的character set。
设置数据库编码(sudo vi /etc/mysql/my.cnf):
[client] default-character-set = utf8 [mysqld] character-set-server = utf8 collation-server = utf8_general_ci
查看设置结果
更改my.cnf之前:
mysql> SHOW VARIABLES LIKE ‘%char%‘; +--------------------------+---------------------------------------------------------------+ | 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/local/mysql-5.6.21-linux-glibc2.5-x86_64/share/charsets/ | +--------------------------+---------------------------------------------------------------+
设置之后,重启mysql服务($ sudo service mysql restart):
mysql> SHOW VARIABLES LIKE ‘%char%‘; +--------------------------+---------------------------------------------------------------+ | 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/local/mysql-5.6.21-linux-glibc2.5-x86_64/share/charsets/ | +--------------------------+---------------------------------------------------------------+
以上是关于mysql设置字符集CHARACTER SET的主要内容,如果未能解决你的问题,请参考以下文章
mysql(5.7.17)字符集设置(character_set/collation)