mysql 查询区分大小写 binary位置要注意

1 mysql 数据库在一般情况下,对与字符类型的查询,是不区分大小写的。

2 使区分大小写的方式

   1 字段设置为 char binary

                         varchar binary

   2 where 语句中添加binary 关键字

  •     select * from userinfo where binary  username = 'along';
  •     select * from userinfo where username =  binary 'along';

   两种语句效率差距甚大,第一种全表扫描不能利用索引,第二种能很好利用索引

   详细的情况,请用 

  •    explain select * from userinfo where binary  username = 'along';
  •     explain   select * from userinfo where username =  binary 'along';

具体查看索引利用情况。

猜你喜欢

转载自alfred-long.iteye.com/blog/2275544