免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1251 | 回复: 0
打印 上一主题 下一主题

mysql中的数据编码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-16 00:41 |只看该作者 |倒序浏览

mysql中的数据编码
发表:2005-12-2  点击: 180次  作者:  转自:
mysql 4.1版本后,对编码的支持大大加强,这是它自己的说法:
MySQL 4.1 can do these things for you:
Store strings using a variety of character sets
Compare strings using a variety of collations
Mix strings with different character sets or collations in the same server, the same database, or even the same table
Allow specification of character set and collation at any level
In these respects, not only is MySQL 4.1 far more flexible than MySQL 4.0, it also is far ahead of other DBMSs
见:
http://dev.mysql.com/doc/mysql/en/charset-general.html

1 character set和collation的区别
character set表示字符集,也就是字符(character)和对应的编码(encoding)合称为character set.
collation是字符间比较的方法,比如binaray, case sensitive, case insensitive。
2 character set, collation的设置
可以通过show variables like "%char"; show variables like "%collation%"分别查看当前的设置情况。
在my.cnf文件中,可以使用:
character-set-server=utf8
collation-server-utf8
设置缺省server的character set, collation,这两个选项从4.1.3版本开始有效。之前版本的设置方法:
default-character-set=utf8
default-collation=utf8
通过上面的设置后,show variables like "%char%"如下所示:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
show variables like "%collation%"显示:
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-------------------+
3 问题
我希望character-set-client, character-set-results,character-set-connection也是utf8, collation-connection也是utf8_general_ci,不知道在my.cnf中如何设置才能做到?
我目前都是先执行set names 'utf8',再作进一步查询。
执行set names 'utf8'后,show variables "%char%", show variables "%collation%"显示所有的变量设置都是utf8的了。
转自:
http://www.bloghome.cn/index.php?op=ViewArticle&articleId=4086&blogId=5



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12056/showart_68121.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP