我有以下 MyISAM 表
mysql> show create table product_desc\G
*************************** 1. row ***************************
Table: product_desc
Create Table: CREATE TABLE `product_desc` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`product_id` int(10) unsigned DEFAULT '0',
`title` varchar(100) DEFAULT NULL,
`description` varchar(5000) DEFAULT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `title` (`title`,`description`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
但是,当我想使用以下命令更改表(添加索引)时,出现错误。
mysql> ALTER TABLE product_desc ADD INDEX `description` (`description`);
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes
奇怪的是,这只发生在 Mac OSX 上,而不是我的 ubuntu 服务器上。所以我检查了我服务器上的结果表并得到了这个:
mysql> show indexes from product_desc;
+------------------------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------------------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| product_desc | 0 | PRIMARY | 1 | id | A | 5 | NULL | NULL | | BTREE | | |
| product_desc | 1 | description | 1 | description | A | 5 | 333 | NULL | YES | BTREE | | |
| product_desc | 1 | title | 1 | title | NULL | 1 | NULL | NULL | YES | FULLTEXT | | |
| product_desc | 1 | title | 2 | description | NULL | 1 | NULL | NULL | YES | FULLTEXT | | |
+------------------------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
6 rows in set (0.00 sec)
有趣的部分是description
索引自动获得 333 前缀长度。所以我的问题是它是如何发生的?为了获得相同的结果,我需要在 MacOS my.cnf 上设置任何配置变量吗?