MySQL 查询时强制区分大小写

让MySQL搜索区分大小写或排序时分大小写方法如下:

 

1.在SQL中强制

SELECT `field` FROM `table` WHERE BINARY `colunm` = ‘xxxxxx’

SELECT `field` FROM `table` WHERE BINARY `colunm` like ‘%xxxxxx%’

 

2.建表时强制

在建表时,添加BINARY属性即可。如果使用PHPMyAdmin建表,直接在属性中选择‘binary’ 即可。

CREATE TABLE table_name (name varchar(20) binary)

 

以上就是让MySQL搜索区分大小写的基本方法。

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.