如果我同时添加两者,那么唯一性约束就会失败,即使我的字段是 UTF-8。可以做什么?我正在运行 5.5.16
mysql> show create table foo_person;
+------------+------------------------------------------------+
| Table | Create Table |
+------------+------------------------------------------------+
| foo_person | CREATE TABLE `foo_person` (
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
+------------+------------------------------------------------+
mysql> INSERT INTO foo_person (`name`) VALUES ('resumé');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO foo_person (`name`) VALUES ('resume');
ERROR 1062 (23000): Duplicate entry 'resume' for key 'PRIMARY'
mysql> select * from foo_person;
+---------+
| name |
+---------+
| resumé |
+---------+
1 row in set (0.00 sec)
似乎 MySQL 不支持 Accent Sensitive 排序规则。(见http://dev.mysql.com/doc/refman/5.6/en/charset-collation -implementations.html )
因此,您唯一的选择是使用二进制排序规则,例如 utf8_bin。但是,这也会使列区分大小写,这与您当前的排序规则不同。
另请参阅https://stackoverflow.com/questions/500826/how-to-conduct-an-accent-sensitive-search-in-mysql