分享

mysql中utf8

 昵称10087950 2018-02-05

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

1)utf8_bin

2)utf8_general_ci

3)utf8_general_cs

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

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

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;

在5.6.10版本中,以上命令执行失败,不支持utf8_genral_cs。

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

以上命令能够执行成功。

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

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

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

以上命令能够执行成功。

insert into test_ci values('alily', 20);
以上命令执行失败,因为utf8_general_ci不区分大小写,两条记录的主键重复。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多