【发布时间】:2019-08-19 11:20:14
【问题描述】:
我运行以下查询:
SELECT name FROM shops ORDER BY name;
当前结果:
ABC shop
ÁDE shop
ALT shop
预期结果应该是:
ABC shop
ALT shop
ÁDE shop
看起来A 和Á 是相等的。 (正确顺序:a
我尝试使用匈牙利排序规则(使用 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
【问题讨论】:
-
@Strawberry 问题已更新。
-
@BrettGregson 这个自定义排序看起来有点老套,但我会试试的
-
为什么是 PHP 标签?您的问题与此无关,除非您想在 PHP 中进行排序。
-
@Peter Kota 不是专家,但它不是 utf8mb4_hu_0900_as_cs 区分重音和大小写的.. 所以它对待
标签: mysql sql character-encoding special-characters collation