开发者社区> 问答> 正文

How to create an Index in MySQL?

已解决

How to create an Index in MySQL?

展开
收起
1780169608831412 2021-10-16 16:45:49 521 0
2 条回答
写回答
取消 提交回答
  • 网络规划设计师、敏捷专家、CISP、ITSS服务经理、ACA全科目、ACP4项、ACE、CBP、CDSP、CZTP等。拥有 PRINCE2 Foundation/Practitioner、CCSK、ITIL、ISO27001、PMP等多项国际认证。 专利5+、期刊10+、知识产权师。核心期刊审稿人。
    采纳回答

    In MySQL, there are different index types, such as a regular INDEX, a PRIMARY KEY, or a FULLTEXT index. You can achieve fast searches with the help of an index. Indexes speed up performance by either ordering the data on disk so it's quicker to find your result or, telling the SQL engine where to go to find your data.

    Example: Adding indexes to the history table:

    ALTER TABLE history ADD INDEX(author(10));
    ALTER TABLE history ADD INDEX(title(10));
    ALTER TABLE history ADD INDEX(category(5));
    ALTER TABLE history ADD INDEX(year);
    DESCRIBE history;
    
    2021-10-16 17:21:47
    赞同 1 展开评论 打赏
  • mysql> alter table books add index `books_index_name` (`name`,`author`);
    Query OK, 0 rows affected (1 min 14.00 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    2021-10-16 17:03:53
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像