mysql中utf8_bin、utf8_general_ci、utf8_general_cs編碼區別

來源:互聯網
上載者:User

標籤:

在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不區分大小寫,兩條記錄的主鍵重複。

 

               

 

mysql中utf8_bin、utf8_general_ci、utf8_general_cs編碼區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.