修改mysql的编码为utf8

Posted by zuzhihui in Linux技术 on 2008/06/21 with No Comments

MySQL的中文编码问题最简单的解决方案是:修改mysql的配置文件/etc/mysql/my.cnf (在CentOS下是/etc/my.cnf),在[mysqld] 和 [client]段都加入如下指令:

default-character-set=utf8

注意:如果没有[client]段,就手工加入[client]段。然后重新启动MySQL即可。验证一下是否生效:

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/share/mysql/charsets/ |
 -------------------------- ---------------------------- 
8 rows in set (0.00 sec)

mysql>

这样新建立的数据库缺省就是UTF8编码了。

标签:

Leave a Comment

Back to Top

2007-2013 © 北京瑞豪开源科技有限公司 京ICP备13004995号-2