设置UTF-8 character set
和collation
MySQL服务器:
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
然后按i并添加以下内容:
... [mysqld] character-set-server=utf8 collation-server=utf8_general_ci ...
按下Esc然后:w再:q!
然后重启服务器:
sudo /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/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec) mysql> show variables like "%collation%"; +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +----------------------+-----------------+ 3 rows in set (0.00 sec)
设置UTF-8 character set
以及collation
数据库和表:
创建数据库时明确指定它:
CREATE DATABASE some_database CHARACTER SET utf8 COLLATE utf8_general_ci;
检查您的配置:
mysql> SHOW CREATE DATABASE ... mysql> SHOW CREATE TABLE ...