Mysql ::错误:指定的密钥太长;最大密钥长度为1000字节 [英] Mysql::Error: Specified key was too long; max key length is 1000 bytes

查看:779
本文介绍了Mysql ::错误:指定的密钥太长;最大密钥长度为1000字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

script/generate acts_as_taggable_on_migration
rake db:migrate

原因

Mysql::Error: Specified key was too long; max key length is 1000 bytes: CREATE  INDEX `index_taggings_on_taggable_id_and_taggable_type_and_context` ON `taggings` (`taggable_id`, `taggable_type`, `context`)

我该怎么办?

这是我的数据库编码:

mysql> SHOW VARIABLES LIKE 'character\_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | latin1 | 
| character_set_connection | latin1 | 
| character_set_database   | utf8   | 
| character_set_filesystem | binary | 
| character_set_results    | latin1 | 
| character_set_server     | latin1 | 
| character_set_system     | utf8   | 
+--------------------------+--------+
7 rows in set (0.00 sec)


推荐答案

这只是一个MySQL问题 -

This is solely a MySQL issue -

MySQL有不同的引擎 - MyISAM,InnoDB,Memory ......

MySQL has different engines - MyISAM, InnoDB, Memory...

MySQL对可用于在列上定义索引的空间量有不同的限制 - 对于MyISAM它是1,000字节;这是InnoDB的767 。并且这些列的数据类型很重要 - 对于VARCHAR,它是3x,因此VARCHAR(100)上的索引将占用300个这些字节(因为100个字符* 3 = 300)。

MySQL has different limits on the amount of space you can use to define indexes on column(s) - for MyISAM it's 1,000 bytes; it's 767 for InnoDB. And the data type of those columns matters - for VARCHAR, it's 3x so an index on a VARCHAR(100) will take 300 of those bytes (because 100 characters * 3 = 300).

要在达到上限值时容纳一些索引,可以根据列数据类型的部分定义索引:

To accommodate some indexing when you hit the ceiling value, you can define the index with regard to portions of the column data type:

CREATE INDEX example_idx ON YOUR_TABLE(your_column(50))

假设 your_column 是VARCHAR(100),上例中的索引仅在前50个字符上。搜索超过第50个字符的数据将无法使用索引。

Assuming that your_column is VARCHAR(100), the index in the example above will only be on the first 50 characters. Searching for data beyond the 50th character will not be able to use the index.

这篇关于Mysql ::错误:指定的密钥太长;最大密钥长度为1000字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆