错误:#1071-指定的密钥太长;最大密钥长度为1000个字节-mysql 5.0.91 [英] Error: #1071 - Specified key was too long; max key length is 1000 bytes - mysql 5.0.91
问题描述
我正在使用mysql 5.0.91,我需要保存URL(有些很小,有些很长).
我想使用varchar(2000)
,但出现错误:
I am using mysql 5.0.91 and I need to save URLs ( some are small and some are very long ).
I want to use varchar(2000)
but I get an error:
#1071-指定的密钥太长;最大密钥长度为1000字节
#1071 - Specified key was too long; max key length is 1000 bytes
在使用mysql 5.0.91的主机上保存URL的最佳方法是什么?
What is the best way to save URLs on my hosting with mysql 5.0.91 ?
推荐答案
您是否在URL列上使用unique=True
? MySQL正在该列上建立唯一索引,并且每个字符使用的字节数取决于编码.
Do you use unique=True
on your urls column? MySQL is building a unique index on that column, and the number of bytes that it uses per character varies depending on the encoding.
例如,如果它是UTF-16,则每个字符将使用2个字节,因此您的varchar(2000)
列将为4000个字节,并且如错误消息所述,最大密钥长度为1000个字节.
If it is UTF-16, for example, it will use 2 bytes per character, so your varchar(2000)
column would be 4000 bytes, and as the error message says, the max key length is 1000 bytes.
因此您可以切换到UTF-8并使用varchar(900)
来解决此问题.
So you can switch to UTF-8 and use varchar(900)
instead to fix this problem.
这篇关于错误:#1071-指定的密钥太长;最大密钥长度为1000个字节-mysql 5.0.91的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!