4 个回答

当然可以,但是这个索引占的空间很大,可以选择字段前多少位做索引

修改:

当然可以,如果直接建立是不可以的,只能在text类型字段上建立带长度的索引,比如这样:alter table test add index idx_text(aaa(10)); 其中,aaa字段类型为text

可以。但必须给出前缀索引长度。

mysql> CREATE TABLE test (text_col TEXT, INDEX(text_col(10)));
Query OK, 0 rows affected (0.20 sec)

官方文档说明如下:
BLOB and TEXT columns also can be indexed, but a prefix length must be given. Prefix lengths are given in characters for nonbinary string types and in bytes for binary string types. That is, index entries consist of the first length characters of each column value for CHAR, VARCHAR, and TEXT columns, and the first length bytes of each column value for BINARY, VARBINARY, and BLOB columns.
create table

不可以的!

引用楼上某位仁兄的回答:可以。但必须给出前缀索引长度。 我的补充:如果对text做索引,用全文索引也许会更加合适(5.6版本以上才支持InnoDB引擎),关于全文索引,请参考InnoDB FULLTEXT Indexes

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题