当在字符串中搜索带点 (.) 的值时,MySQL 查询返回 0 行
如果我尝试在 mysql 数据库中搜索一个值,并且该字符串值中包含点,则查询将返回 0 行。示例:
SELECT * FROM table WHERE `username`='marco.polo' --> 0 rows
SELECT * FROM table WHERE `username` LIKE '%.polo%' --> 0 rows
SELECT * FROM table WHERE `username` LIKE 'polo' --> Success
将服务器和数据库移至其他位置后出现此情况。我知道点是一组扩展正则表达式,但它不应该应用于 equal 或 LIKE 运算符,只是因为我在查询中不使用 REGEXP。
我已经在本地数据库上测试了相同的查询,效果很好。 mysql 中是否有一个特殊的设置以不同于通常的方式处理点?
If I try to search for a value in mysql database and the string value contains dot in it, query returns 0 rows. Example:
SELECT * FROM table WHERE `username`='marco.polo' --> 0 rows
SELECT * FROM table WHERE `username` LIKE '%.polo%' --> 0 rows
SELECT * FROM table WHERE `username` LIKE 'polo' --> Success
This appeared after moving server and database to another place. I know that dot is a set of extended regular expressions, but it should not apply to equal nor LIKE operator, simply because I don't use REGEXP in query.
I've tested the same query on my local database and it works fine.
Could there be a special setting in mysql that treats dot differently than it usually does?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
user1084605,我尝试复制该问题(使用MySQL版本5.1.37),但得到与您完全相反的结果。请参阅下文:
根据 MySQL 文档,使用 LIKE 运算符时唯一的特殊字符是“%”(百分比:匹配 0、1 或多个字符)和“_”(下划线:匹配一个且仅一个字符)。
http://dev.mysql.com/doc/refman /5.0/en/string-comparison-functions.html
一个“。” (句点) 对于 MySQL 的 REGEXP 运算符确实具有特殊含义,但它仍应与列中的字面句点匹配。
http://dev.mysql.com/doc/refman/5.0/en /regexp.html
你能复制我上面运行的 SQL 语句并将你的结果粘贴到回复中吗?
user1084605, I tried to replicate the problem (using MySQL version 5.1.37), but got exactly the opposite results as you. See below:
According to the MySQL docs, the only special characters when using the LIKE operator are "%" (percent: matches 0, 1, or many characters) and "_" (underscore: matches one and only one character).
http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
A "." (period) does have special meaning for MySQL's REGEXP operator, but it should still match a literal period in your column.
http://dev.mysql.com/doc/refman/5.0/en/regexp.html
Can you replicate the SQL statements I ran above and paste your results in reply?
下面的查询处理列中只有 DOT 运算符时的情况。
The below query takes care of the scenario when we have only DOT operator in the columns.
正如 @cen 已经提到的,字符集可能会导致该问题。
我有这个示例:
这是我收到的 .sql 转储中的。
所以,当我尝试用这封电子邮件获取对象时
我无法得到它。
As @cen already mentioned, character set can causes that problem.
I have had this sample:
this is was in the .sql dump, which I receive.
So, when I was trying to fetch object with this email
I couldn't get it.