【问题标题】:ERROR 1062 (23000): Duplicate entry '?' for key 'PRIMARY' with two differents entries错误 1062 (23000):重复的条目“?”对于具有两个不同条目的键 'PRIMARY'
【发布时间】:2014-04-15 03:11:19
【问题描述】:

我正在尝试将包含大量日文汉字字符的表从 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 |
+--------------------------+--------------------+

在那之后没有任何变化......有什么想法吗?

谢谢

最好的问候

【问题讨论】:

    标签: mysql utf8mb4


    【解决方案1】:

    根据排序规则,这两个字符可能被视为等效字符。 您可以尝试另一种排序规则 - utf8mb4_bin,但是您必须注意将应用程序代码中的所有值小写以确保主键不区分大小写。

    或者,您可以在此数据库中查找您在示例中提供的字符(我不能发布超过 2 个链接,抱歉): http://codepoints.net/

    它们的 UTF 代码点是: U+20089 U+2000B

    在此处查看标准排序映射:http://www.unicode.org/charts/uca/

    我在任何 Unicode 归类映射中都找不到这两个字符,但是在许多情况下,拉丁字符带有变音符号(例如“Ç”和“C”),它们在 utf8 不区分大小写的归类映射中被定义为等价物.

    【讨论】:

    • 另一个在 utf8mb4 中被视为相等的字符是“ss”和“ß”(eszett)。
    猜你喜欢
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 2017-11-28
    相关资源
    最近更新 更多