如何在mysql中搜索精确的字符串
我正在尝试在 mysql 中搜索字符串的精确匹配。该字符串是“nrew”。但是当我执行以下查询时,我仍然得到结果:
SELECT UserID FROM sys_users WHERE UserID='NREW'
SELECT UserID FROM sys_users WHERE UserID='NrEw'
请帮忙。
I'm trying to search for an exact match of a string in mysql. The string is 'nrew'. But when I do the queries below, I still get a result:
SELECT UserID FROM sys_users WHERE UserID='NREW'
SELECT UserID FROM sys_users WHERE UserID='NrEw'
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
MySQL 用于进行比较的默认排序规则不区分大小写。您需要指定区分大小写的排序规则或二进制。您可以在创建列时或在查询中执行此操作。
例如:
正确的排序规则取决于您的字符集。对于默认的
latin1
,您可以使用latin1_bin
。对于utf8
,utf8_bin
。The default collation which MySQL uses to make comparisons is case insensitive. You need to specify a case sensitive collation or binary. You can either do this when creating the column, or in the query.
For example:
The proper collation depends on your character set. For
latin1
, the default, you can uselatin1_bin
. Forutf8
,utf8_bin
.可以使用关键字Binary,
参考这里
You can use keyword Binary,
refer to here
一种方法是使用
LIKE BINARY
而不是=
:One method is to use
LIKE BINARY
instead of=
:尝试一下:http://www.devx.com/tips/Tip/13043
或者尝试 COLLATE
http://aspadvice.com/blogs/ssmith/archive/2007/09/30/Case-Sensitive-or-Insensitive-SQL-Query.aspx
Give this is try: http://www.devx.com/tips/Tip/13043
Or try COLLATE
http://aspadvice.com/blogs/ssmith/archive/2007/09/30/Case-Sensitive-or-Insensitive-SQL-Query.aspx