mysql 不区分大小写的解决

mysql查询默认是不区分大小写的 如:

select * from some_table where str=‘abc';
select * from some_table where str='ABC';

得到的结果是一样的,如果我们需要进行区分的话可以按照如下方法来做:

 

 

第一种方法:

要让mysql查询区分大小写,可以:

select * from some_table where binary str='abc'
select * from some_table where binary str='ABC'

 

 

第二方法:

在建表时时候加以标识
create table some_table(
     str char(20) binary  
)

 

 

原理:

 

对于CHAR、VARCHAR和TEXT类型,BINARY属性可以为列分配该列字符集的 校对规则。BINARY属性是指定列字符集的二元 校对规则的简写。排序和比较基于数值字符值。因此也就自然区分了大小写。
posted on 2018-12-24 15:56  战神V祝福  阅读(529)  评论(0编辑  收藏  举报