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 <database> default character set utf8 default collate utf8_bin;
或者修改已有数据库
mysql> alter database <database> default character set utf8 default collate utf8_bin;
* 查看mysql支持的所有的COLLATION
mysql> SHOW COLLATION;
本文出自:亿恩科技【www.enkj.com】
服务器租用/服务器托管中国五强!虚拟主机域名注册顶级提供商!15年品质保障!--亿恩科技[ENKJ.COM]
|