运算符喜欢,字段类型时间戳和西里尔字母? MySQL Bug?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了运算符喜欢,字段类型时间戳和西里尔字母? MySQL Bug?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2604字,纯文字阅读大概需要4分钟。
内容图文
好像是MySQL Bug;
请求:
SELECT *
FROM table
WHERE (
id LIKE '%тест 199%'
OR `user` LIKE '%тест 199%'
OR `user_datetime` LIKE '%тест 199%'
OR `user_comments` LIKE '%тест 199%' )
ORDER BY id desc
LIMIT 0, 10
[Err] 1271-操作“赞”的排序规则非法混合
而当我们使用拉丁语.
请求:
SELECT *
FROM table
WHERE (
id LIKE '%test 199%'
OR `user` LIKE '%test 199%'
OR `user_datetime` LIKE '%test 199%'
OR `user_comments` LIKE '%test 199%' )
ORDER BY id desc
LIMIT 0, 10
请求成功;
怎么处理呢?
我所有的请求都是自动生成的,我无法更改逻辑coz函数生成器,因此有很多依赖性.
设定:
SET NAMES utf8
Character set utf8 -- UTF-8 Unicode
Collation utf8_general_ci
UPD的@eggyal
Request:
SHOW CREATE TABLE `comments`
Response:
CREATE TABLE `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user` varchar(255) NOT NULL DEFAULT '',
`user_datetime` timestamp NULL DEFAULT NULL,
`user_comments` varchar(128) DEFAULT NULL,
UNIQUE KEY `id` (`id`) USING BTREE,
KEY `user_comments` (`user_comments`),
) ENGINE=InnoDB AUTO_INCREMENT=128456 DEFAULT CHARSET=utf8
MySQL 5.5.10版
解决方法:
您正在使用哪个版本的MySQL?如the manual中所述:
As of MySQL 5.5.3, implicit conversion of a numeric or temporal value to string produces a value that has a character set and collation determined by the 07001 and 07002 system variables. (These variables commonly are set with 07003. For information about connection character sets, see 07004.)
This change means that such a conversion results in a character (nonbinary) string (a 07005, 07006, or 07007 value), except when the connection character set is set to
binary
. In that case, the conversion result is a binary string (a 07008, 07009, or 070010 value).Before MySQL 5.5.3, an implicit conversion always produced a binary string, regardless of the connection character set. Such implicit conversions to string typically occur for functions that are passed numeric or temporal values when string values are more usual, and thus could have effects beyond the type of the converted value.
因此,如果您使用的MySQL版本早于5.5.3,而与SET NAMES无关,则使用LIKE运算符时将TIMESTAMP列隐式转换为字符串将始终导致二进制字符集的字符串(奇怪的是,这是sqlfiddle也是如此,它声称是5.5.20);由于无法将此类字符串与utf8字符集中的字符串进行比较,因此必须将user_datetime列显式转换为UTF-8字符串:
SELECT *
FROM `comments`
WHERE (
`id` LIKE '%тест 199%'
OR `user` LIKE '%тест 199%'
OR CONVERT(`user_datetime` USING utf8) LIKE '%тест 199%'
OR `user_comments` LIKE '%тест 199%'
)
ORDER BY `id` DESC
LIMIT 0, 10
内容总结
以上是互联网集市为您收集整理的运算符喜欢,字段类型时间戳和西里尔字母? MySQL Bug?全部内容,希望文章能够帮你解决运算符喜欢,字段类型时间戳和西里尔字母? MySQL Bug?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。