我运行以下查询:
SELECT name FROM shops ORDER BY name;
当前结果:
ABC shop
ÁDE shop
ALT shop
预期结果应该是:
ABC shop
ALT shop
ÁDE shop
看起来 A
和 Á
是相等的。 (正确顺序:a < á < e < é < o < ó < ö...)
我尝试使用匈牙利语排序规则(使用 mysql 8.0.17):
ALTER DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_hu_0900_ai_ci;
我发现 mysql 团队已经在 mysql 8.0.1 中修复了这个问题:https://bugs.mysql.com/bug.php?id=12519
SHOW CREATE TABLE 商店;
| shops | CREATE TABLE `shops` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`address_id` bigint(20) unsigned DEFAULT NULL,
`shop_category_id` bigint(20) unsigned DEFAULT NULL,
`shop_chain_id` bigint(20) unsigned DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`partner_id` bigint(20) unsigned DEFAULT NULL,
`location_id` bigint(20) unsigned DEFAULT NULL,
`is_active` tinyint(1) NOT NULL DEFAULT '1',
`user_id` bigint(20) unsigned DEFAULT NULL,
`deputy_user_id` bigint(20) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `shops_address_id_foreign` (`address_id`),
KEY `shops_shop_category_id_foreign` (`shop_category_id`),
KEY `shops_shop_chain_id_foreign` (`shop_chain_id`),
KEY `shops_partner_id_foreign` (`partner_id`),
KEY `shops_location_id_foreign` (`location_id`),
KEY `shops_user_id_foreign` (`user_id`),
KEY `shops_deputy_user_id_foreign` (`deputy_user_id`),
CONSTRAINT `shops_address_id_foreign` FOREIGN KEY (`address_id`) REFERENCES `addresses` (`id`) ON DELETE SET NULL,
CONSTRAINT `shops_deputy_user_id_foreign` FOREIGN KEY (`deputy_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
CONSTRAINT `shops_location_id_foreign` FOREIGN KEY (`location_id`) REFERENCES `locations` (`id`) ON DELETE SET NULL,
CONSTRAINT `shops_partner_id_foreign` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE CASCADE,
CONSTRAINT `shops_shop_category_id_foreign` FOREIGN KEY (`shop_category_id`) REFERENCES `shop_categories` (`id`) ON DELETE SET NULL,
CONSTRAINT `shops_shop_chain_id_foreign` FOREIGN KEY (`shop_chain_id`) REFERENCES `shop_chains` (`id`) ON DELETE SET NULL,
CONSTRAINT `shops_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=564 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hu_0900_ai_ci
最佳答案
没有简单的解决方案:
计划 A:编写自己的排序规则。
B 计划:在 bugs.mysql.com 上写一个错误,提示即使在 8.0.17 中,utf8mb4_hu_0900_ai_ci
也是“不正确的”。
(同时,我怀疑 utf8mb4_hungarian_ci
保留了 5.7 排序规则以实现向后兼容性。)
关于匈牙利语字符的 MySQL 错误 ORDER BY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57555718/