gpt4 book ai didi

MySQL唯一键似乎只取varchar的前17个字符

转载 作者:行者123 更新时间:2023-11-29 20:47:51 25 4
gpt4 key购买 nike

我试图找出为什么我的数据库不接受 MySQL v5.7.12 上的复合唯一键并使用 InnoDB。我发现了许多关于唯一 key 大小的限制以及达到这些限制时出现的问题的线程,但我的大小远未接近这些限制(甚至少于 255 个字符!)。 MySQL 文档说 key 限制是 3072 字节! http://dev.mysql.com/doc/refman/5.7/en/innodb-restrictions.html

为了简单起见,我提供了相关字段信息:

| ascii_name      | varchar(200)     | YES  |     | NULL    |       |
| feature_class | char(1) | YES | | NULL | |
| feature_code | varchar(10) | YES | | NULL | |

我正在尝试添加复合唯一键

mysql> alter table geonames_geonames add unique (ascii_name,feature_code,feature_class);
ERROR 1062 (23000): Duplicate entry 'Rudkhaneh-ye Shur-STM-H' for key 'ascii_name'
mysql>

根据错误和表的内容,我认为它仅使用该字段的前 17 个字符。但为什么?如果我检查表格

mysql> select ascii_name,feature_code,feature_class from geonames_geonames where name like 'Rudkhaneh-ye Shur-%';
+-------------------------------+--------------+---------------+
| ascii_name | feature_code | feature_class |
+-------------------------------+--------------+---------------+
| Rudkhaneh-ye Shur-e Dehram | STM | H |
| Rudkhaneh-ye Shur-e Sabzevar | STM | H |
| Rudkhaneh-ye Shur-e Sar Dasht | STM | H |
+-------------------------------+--------------+---------------+
3 rows in set (0.00 sec)

mysql>

我也尝试给出尺寸,但结果是相同的。

mysql> alter table geonames_geonames add unique (ascii_name(200),feature_code,feature_class);
ERROR 1062 (23000): Duplicate entry 'Rudkhaneh-ye Shur-STM-H' for key 'ascii_name'
mysql>

那么,这个限制从何而来呢?有可能增加吗?欢迎任何描述此限制的文档链接!

谢谢!

最佳答案

显然错误只打印值并在其后添加破折号,所以确实我有重复的行:(我只是在看错误的条目...

mysql> select ascii_name,feature_code,feature_class from geonames_geonames where name like 'Rudkhaneh-ye Shur%';
+--------------------------------+--------------+---------------+
| ascii_name | feature_code | feature_class |
+--------------------------------+--------------+---------------+
| Rudkhaneh-ye Shur | AREA | L |
| Rudkhaneh-ye Shur | SBED | T |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STM | H |
| Rudkhaneh-ye Shur | STMI | H |
| Rudkhaneh-ye Shur | STMI | H |
| Rudkhaneh-ye Shur | STMI | H |
| Rudkhaneh-ye Shur | STMI | H |
| Rudkhaneh-ye Shur | STMI | H |
| Rudkhaneh-ye Shur | STMX | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STM | H |
| Rudkhaneh-ye Shur Ab | STMI | H |
| Rudkhaneh-ye Shur Ab | STMI | H |
| Rudkhaneh-ye Shur Ab Qandu | STMI | H |
| Rudkhaneh-ye Shur Barik | STM | H |
| Rudkhaneh-ye Shur Bid | STM | H |
| Rudkhaneh-ye Shur Chah-e Nahr | STM | H |
| Rudkhaneh-ye Shur Chay | STM | H |
| Rudkhaneh-ye Shur Chay | STM | H |
| Rudkhaneh-ye Shur Chay | STM | H |
| Rudkhaneh-ye Shur Ghamish | STMI | H |
| Rudkhaneh-ye Shur Gol Shang | STM | H |
| Rudkhaneh-ye Shur Goleh Gah | STM | H |
| Rudkhaneh-ye Shur Jajarm | STM | H |
| Rudkhaneh-ye Shur Khar Turan | STM | H |
| Rudkhaneh-ye Shur Mahur | STMI | H |
| Rudkhaneh-ye Shur Mur Dar Bala | STM | H |
| Rudkhaneh-ye Shur Naseri | STMI | H |
| Rudkhaneh-ye Shur Shah Gheyb | STM | H |
| Rudkhaneh-ye Shur-e Dehram | STM | H |
| Rudkhaneh-ye Shur-e Sabzevar | STM | H |
| Rudkhaneh-ye Shur-e Sar Dasht | STM | H |
| Rudkhaneh-ye Shurab | STM | H |
| Rudkhaneh-ye Shurab | STM | H |
| Rudkhaneh-ye Shurab | STM | H |
| Rudkhaneh-ye Shurab | STM | H |
| Rudkhaneh-ye Shurab | STM | H |
| Rudkhaneh-ye Shurabeh | STM | H |
| Rudkhaneh-ye Shurabeh | STM | H |
| Rudkhaneh-ye Shurak | STM | H |
| Rudkhaneh-ye Shurak | STMI | H |
| Rudkhaneh-ye Shurani | STMI | H |
| Rudkhaneh-ye Shurava | STMI | H |
| Rudkhaneh-ye Shureh | STM | H |
| Rudkhaneh-ye Shureh | STM | H |
| Rudkhaneh-ye Shureh | STM | H |
| Rudkhaneh-ye Shureh Kand | STM | H |
| Rudkhaneh-ye Shureh Kot | STM | H |
| Rudkhaneh-ye Shureh Lang | STMI | H |
| Rudkhaneh-ye Shuru | STM | H |
| Rudkhaneh-ye Shurug | STM | H |
| Rudkhaneh-ye Shurug | STM | H |
+--------------------------------+--------------+---------------+
134 rows in set (0.00 sec)

mysql>

关于MySQL唯一键似乎只取varchar的前17个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38310625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com