mysql-索引

创建test表

create table test(
id int,
name varchar(10) not null,
age int default 18,
passwd varchar(12),
article text
);

主键索引

alter table test add primary key auto_increment (id);

唯一索引

alter table test add unique (name);       (可同时添加多个字段)

普通索引

alter table test add index (age);  (可同时添加多个字段)

全文索引

alter table test add fulltext (article);

mysql> show create table testG
*************************** 1. row ***************************
       Table: test
Create Table: CREATE TABLE `test` (
  `id` int(11) NOT NULL,
  `name` varchar(10) NOT NULL,
  `age` int(11) DEFAULT '18',
  `passwd` varchar(12) DEFAULT NULL,
  `article` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`),
  KEY `age` (`age`),
  FULLTEXT KEY `article` (`article`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
原文地址:https://www.cnblogs.com/tangpg/p/8724025.html