zoukankan      html  css  js  c++  java
  • mysql中utf8_bin、utf8_general_ci、utf8_general_cs编码区别

    在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_bin values('alice', 18);

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

                   

  • 相关阅读:
    CodeForces gym Nasta Rabbara lct
    bzoj 4025 二分图 lct
    CodeForces 785E Anton and Permutation
    bzoj 3669 魔法森林
    模板汇总——快读 fread
    bzoj2049 Cave 洞穴勘测 lct
    bzoj 2002 弹飞绵羊 lct裸题
    HDU 6394 Tree 分块 || lct
    HDU 6364 Ringland
    nyoj221_Tree_subsequent_traversal
  • 原文地址:https://www.cnblogs.com/avivahe/p/5428069.html
Copyright © 2011-2022 走看看