MySQL 大小写不敏感

环境

//MySQL client 
select version();
5.7.28-log

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

character_set_client    utf8mb4  //
character_set_connection    utf8mb4
character_set_database  utf8mb4  //
character_set_filesystem    binary
character_set_results   utf8mb4
character_set_server    utf8
character_set_system    utf8
collation_connection    utf8mb4_general_ci
collation_database  utf8mb4_general_ci
collation_server    utf8_general_ci

数据库的默认的CHARACTER SET 是utf8mb4,collation 是utf8mb4_general_ci。

表结构

//建表语句
CREATE TABLE `test` (
   `id` bigint(20) NOT NULL,
   `code` varchar(50) NOT NULL,
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='test';

insert into test values(1,'A');
insert into test values(2,'a');

collation为utf8mb4_general_ci是大小写不敏感的,修改成utf8mb4_bin。

修改字段SQL如下

ALTER TABLE `test` CHANGE `code` `code` varchar(20)  CHARACTER SET utf8mb4 COLLATE utf8mb4_bin   not null;

参考资料

全面了解mysql中utf8和utf8mb4的区别
Character Sets and Collations.

你可能感兴趣的:(MySQL 大小写不敏感)