Seems like MySQL Bug;
Request:
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 – Illegal mix of collations for operation ‘like’
And when we use latinic.
Request:
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
Request Success;
How to deal with it?
All of my request are generated automatically, i cant change logic coz function generator has many dependence.
Settings:
SET NAMES utf8
Character set utf8 -- UTF-8 Unicode
Collation utf8_general_ci
UPD for @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 Version 5.5.10
What version of MySQL are you using? As stated in the manual:
Therefore the implicit conversion of your
TIMESTAMPcolumn to a string that occurs when using theLIKEoperator will always result in a string of thebinarycharacter set if you are using a version of MySQL earlier than 5.5.3 irrespective ofSET NAMES(curiously this is also the case on sqlfiddle, which claims to be 5.5.20); since such strings cannot be compared with strings in theutf8character set, you must explicitly convert youruser_datetimecolumn to a UTF-8 string: