我正在尝试将包含大量日文汉字字符的表从 SQLite 导入 MySQL。 我尝试插入数据的表格如下所示:
+--------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+----------+------+-----+---------+-------+
| literal | char(10) | NO | PRI | NULL | |
| grade | int(11) | YES | | NULL | |
| stroke_count | int(11) | YES | | NULL | |
| freq | int(11) | YES | | NULL | |
| jlpt | int(11) | YES | | NULL | |
当我尝试
INSERT INTO main VALUES('𠂉',NULL,2,NULL,NULL);
我得到了下一个错误:
mysql>
ERROR 1062 (23000): Duplicate entry '?' for key 'PRIMARY'
And if try to look up that entry i get:
select * from main where literal = '𠂉';
+---------+-------+--------------+------+------+
| literal | grade | stroke_count | freq | jlpt |
+---------+-------+--------------+------+------+
| 𠀋 | NULL | 4 | NULL | NULL |
+---------+-------+--------------+------+------+
1 row in set (0.00 sec)
为什么查找'𠂉'它显示为'𠀋'?
我认为这可能与 UTF8 编码有关,所以我按照 link 的说明将所有 Db 和表重新配置为 utf8mb4 .
这是mysql的配置:
mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name | Value |
+--------------------------+--------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+--------------------+
在那之后没有任何变化......有什么想法吗?
谢谢
最好的问候
最佳答案
根据排序规则,这两个字符可能被视为等同的。 您可以尝试另一种排序规则 - utf8mb4_bin,但随后您必须注意对应用程序代码中的所有值进行小写处理,以确保主键不区分大小写。
或者,您可以在此数据库中查找您在示例中提供的字符(抱歉,我不能发布超过 2 个链接): http://codepoints.net/
它们的 UTF 代码点是: U+20089 U+2000B
在此处查看标准归类图:http://www.unicode.org/charts/uca/
我在任何 Unicode 归类映射中都找不到这两个字符,但在很多情况下,拉丁字符都带有变音符号(例如“Ç”和“C”),它们在 utf8 不区分大小写的归类映射中被定义为等效字符.
关于mysql - 错误 1062 (23000) : Duplicate entry '?' for key 'PRIMARY' with two differents entries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23074010/