1. 编辑/etc/my.cnf文件, 在"[client]"下添加"default-character-set=utf8"
2. 编辑/etc/my.cnf文件, 在"[mysqld]"下添加"default-character-set=utf8"
3. 重新启动mysql服务
# sudo /etc/init.d/mysqld restart
* 查看系统字符集和排序方式
mysql> SHOW VARIABLES LIKE 'collation/_%';
+--------------------------+--------+
| 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 |
+--------------------------+--------+
mysql> SHOW VARIABLES LIKE 'character/_set/_%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_bin |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
4. 设置数据库字符集
mysql> create database default character set utf8 default collate utf8_bin;
或者修改已有数据库
mysql> alter database default character set utf8 default collate utf8_bin;
* 查看mysql支持的所有的COLLATION
mysql> SHOW COLLATION;