就像 MySQL 中区分大小写一样
我有一个 MySQL 查询:
SELECT concat_ws(title,description) as concatenated HAVING concatenated LIKE '%SearchTerm%';
并且我的表使用 MyISAM 编码为 utf8_general_ci 。
搜索似乎区分大小写。
我不知道如何解决它。出了什么问题和/或如何修复它?
I have a MySQL query:
SELECT concat_ws(title,description) as concatenated HAVING concatenated LIKE '%SearchTerm%';
And my table is encoded utf8_general_ci with MyISAM.
Searches seem to be case sensitive.
I can't figure out how to fix it. What's going wrong and/or how do I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
就性能而言,这是一个更好的解决方案:
当任何操作数是二进制字符串时,字符串比较区分大小写。
另一种选择是使用
COLLATE
,A much better solution in terms of performance:
String comparision is case-sensitive when any of the operands is a binary string.
Another alternative is to use
COLLATE
,试试这个:
或(让你看到区别)
Try this:
or (to let you see the difference)
在此方法中,您不必选择搜索字段:
In this method, you do not have to select the searched field:
检查表模式中提到的CHARSET:
基于CHARSET,您可以尝试以下操作。
以下是对我有用的案例,CHARSET=latin1,MySQL 版本=5.6。
Check CHARSET mentioned in the table schema:
Based on CHARSET, you can try the following.
Following are the cases which worked for me, CHARSET=latin1, MySQL version = 5.6.
只是为了完成,以防有帮助:
如 https 上所述: //dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html,对于默认字符集,非二进制字符串比较默认不区分大小写。
因此,执行不区分大小写比较的一种简单方法是将字段转换为 CHAR、VARCHAR 或 TEXT 类型。
以下是针对单个字段进行检查的示例:
Just for completion, in case it helps:
As stated on https://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html, for default character sets, nonbinary string comparisons are case insensitive by default.
Therefore, an easy way to perform case-insensitive comparisons is to cast the field to CHAR, VARCHAR or TEXT type.
Here is an example with a check against a single field:
在本例中,由于表中使用的排序规则而出现此问题。您已使用
utf8_general_ci
作为排序规则。如果排序规则更改为 utf8_general_ci ,则搜索将不区分大小写。因此,一种可能的解决方案是更改排序规则。
This problem is occurring in this case because of the collation used in the table. You have used
utf8_general_ci
as collation. If the collation is changed toutf8_general_ci
then the searches will not be case sensitive.So, one possible solution is to change the collation.
这是工作代码:
This is the working code:
这也有效:
This works also: