在MySQL查询匹配字符串字段时,发现大小写不敏感的问题,如下:
执行示例 select * from student 如下:

执行 select * from student where gender = 'girl' ;
select * from student where gender = 'GIRL' ;
select * from student where gender = 'Girl' ;
结果都是一样的:

MySQL默认是不区分大小写的,但是在很多情况下需要大小敏感。
如果某字段需要区分大小写,可以在定义该字段时指定binary属性。
ALTER TABLE `student`
MODIFY COLUMN `gender` varchar(32) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `name`;
然后查询:select * from student where gender = 'GIRL' ;

或者也可以在查询语句中,使用binary命令强行区分大小写:select * from student where BINARY gender = 'Girl' ;

也可以把该字段的排序规则设为utf8_bin。
|