MySQL VARBINARY WHERE字符串比较不起作用

时间:2015-10-06 14:21:58

标签: mysql sql string where varbinary

我有一个MySQL表,其字段是varbinary。它们包含为快速查找而编制索引的字符串。在一台服务器上,查找似乎工作得很好。在另一台服务器上,它们返回空集。导致结果中服务器出现差异的原因是什么?

表格定义

CREATE TABLE IF NOT EXISTS `%s` (
  `url` varbinary(2000) NOT NULL,
  `category` varbinary(64) NOT NULL,
  `type` binary(1) NOT NULL,
  PRIMARY KEY (`url`(256)),
  KEY `category` (`category`),
  KEY `type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

服务器1上的结果(MySQL 5.6.26)

mysql> SELECT `category` FROM `blacklist` WHERE (`category`='porn') AND ((`type`='d' AND `url`='186.59') OR (`type`='d' AND `url`='209.35.186.59') OR (`type`='d' AND `url`='59')) LIMIT 0, 1;                                               
+----------+                                                                                                                                                                                                                                 
| category |                                                                                                                                                                                                                                 
+----------+                                                                                                                                                                                                                                 
| porn     |                                                                                                                                                                                                                                 
+----------+                                                                                                                                                                                                                                 
1 row in set (0.00 sec)

服务器2上的结果(MySQL 5.5.44-0 + deb8u1)

mysql> SELECT `category` FROM `blacklist` WHERE (`category`='porn') AND ((`type`='d' AND `url`='186.59') OR (`type`='d' AND `url`='209.35.186.59') OR (`type`='d' AND `url`='59')) LIMIT 0, 1;
Empty set (0.00 sec)

转储值服务器1(usig mysqldump)

INSERT INTO `blacklist` VALUES ('','ads','u'),('1.im.cz/reklama','ads','u'),('12.16.1.10/web_GIF','publicite','u'),('12.16.1.10/~web_ani','publicite','u');

转储值服务器2(使用phpmyadmin)

INSERT INTO `blacklist` (`url`, `category`, `type`) VALUES
('', 0x706f726e, 0x64),
(0x312e696d2e637a2f72656b6c616d61, 0x616473, 0x75),
(0x31322e31362e312e31302f7765625f474946, 0x7075626c6963697465, 0x75),
(0x31322e31362e312e31302f7e7765625f616e69, 0x7075626c6963697465, 0x75);

0 个答案:

没有答案