当前位置: 首页 > 图文教程 > 数据库 > MYSQL > mysql中的数据编码

MYSQL
五种MySQL数据库可靠性方案的分析和比较
怎样在Mysql中直接储存图片
mysql的本地备份和双机相互备份脚本
详细讲解Linux环境下MySQL 5.1安装步骤
实例讲解在MySQL中如何导出整个数据库
讲解MySQL索引的概念及数据库索引的应用
教你在MySQL中快速复制表格作为测试数据
删除完全重复和部分关键字段重复的记录
MySQL各存储引擎的区别及其启动方法
MySQL在网络安全方面采取的主要措施
在MySQL中执行SQL语句时的几个注意点
MySQL改善数据装载操作效率的策略
设计高效合理的MySQL查询语句讲解
MySQL用户Root密码为弱口令的攻击
MySQL数据库接口的VC具体实现与应用
在MySQL数据库增加新用户权限简介
MySQL中文模糊检索问题的解决方法
MySQL的数据类型和建库策略详解
利用图形界面从SQL导入导出到MySQL
MySQL数据库应该如何对抗解密高手

MYSQL 中的 mysql中的数据编码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 83 ::
收藏到网摘: n/a

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的了。