標籤:
在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編碼區別