`
FZtree
  • 浏览: 105353 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

mysql 的 case (in)sensitivity

 
阅读更多

在mysql中存在着各种utf8编码格式,如下表:

 

1)utf8_bin

utf8_bin将字符串中的每一个字符用二进制数据存储,区分大小写。

 

2)utf8_general_ci

utf8_genera_ci不区分大小写,ci为case insensitive的缩写,即大小写不敏感。

 

3)utf8_general_cs

utf8_general_cs区分大小写,cs为case sensitive的缩写,即大小写敏感。

 

执行如下命令:

 

create table test_bin (

  name varchar(32) not null primary key,

  age int unsigned not null

) engine = InnoDB COLLATE=utf8_bin;

 

create table test_ci (

  name varchar(32) not null primary key,

  age int unsigned not null

) engine = InnoDB COLLATE=utf8_general_ci;

 

create table test_cs (

  name varchar(32) not null primary key,

  age int unsigned not null

) engine = InnoDB COLLATE=utf8_general_cs;

 

1,2命令成功 3执行失败,不支持utf8_genral_cs。

 

insert into test_bin values('Alice', 18);

insert into test_bin values('alice', 20);

以上命令能够执行成功,因为utf8_bin是以十六进制方式存储数据,两条记录的主键不重复。

 

insert into test_ci values('Alice', 18);

insert into test_ci values('alilce', 20);

以上命令执行失败,因为utf8_general_ci不区分大小写,两条记录的主键重复。

 

最后 看下官方的文档

case (in)sensitivity  

https://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html

 

problems 

https://bugs.mysql.com/bug.php?id=65830 

https://bugs.mysql.com/bug.php?id=50909 

https://bugs.mysql.com/bug.php?id=63164

 

分享到:
评论
1 楼 FZtree 2018-08-20  
以上问题的解决思路官方文档里面也给出了。

非二进制字符串(CHAR, VARCHAR, TEXT)
  二进制串(BINARY, VARBINARY, BLOB)

相关推荐

Global site tag (gtag.js) - Google Analytics