MySQL基本索引优化

       索引:是帮助DB高效获取数据的数据结构,有:B+tree、B-tree等,索引相当于一本书的目录,关键字index。

(单列索引)唯一索引:就是索引的值必须唯一,关键字段:unique index

创建唯一索引: alter table 表名 add unique index 索引名(列名); 

                             create unique index 索引名 on Table(列名);

例如:表:tbl_user 、含有字段:user_name

for example: alter table tbl_user add unique index username(user_name);

for example: create unique index username on tbl_user(user_name);

删除唯一索引:alter table 表名 drop index 索引名;

                             drop index 索引名 on 表名;

for example: alter table tbl_user drop index username;

for example:  drop index username on tbl_user;

多列索引:也叫复合索引,例如:

create table test3 ( id int not null primary key auto_increment,

                              uname char(8) not null default '',

                              password char(12) not null,

                             index(uname,password))type=myisam;

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 观其大纲 page 01 基础知识 1 MySQL数据库概要 2 简单MySQL环境 3 数据的存储和获取 4 M...
    周少言阅读 3,176评论 0 33
  • 之前的文章一直在规避索引的建立去优化数据库,不是不想讲,而是这个太重要,必须抽出来讲。今天我们就来研究下数据库索引...
    sherlock_6981阅读 3,025评论 0 23
  • 今早办公室里的同事异常兴奋,不知谁先开的口说今年的高考作文,就讨论开了,说当今中国做好事的结局是很令人心寒,说起来...
    清林0阅读 543评论 0 0
  • 1.Spark介绍 Spark,是一种通用的大数据计算框架。正如Hadoop的MapReduce、Hive引擎,以...
    泊牧阅读 269评论 0 1
  • 忐忑的心情犹如迷雾,拨不开,沉重。 说来也怪,明明是自己工作的不开心,平台也不好,想要换个平台,怎么反而好像被道德...
    聊个二毛阅读 90评论 0 0