mysql索引
2016-10-31 09:22
176 查看
1 索引的创建
1.1 普通索引
1.2 .唯一索引
mysql> create UNIQUE index index_unique on user1(username);
mysql> show create table user1\G;
Table: user1
Create Table: CREATE TABLE `user1` (
`id` int(11) DEFAULT NULL,
`username` char(10) DEFAULT NULL,
`password` varchar(20) DEFAULTNULL,
`address` varchar(20) DEFAULTNULL,
UNIQUE KEY `index_unique`(`username`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk
1 row in set (0.00 sec)
mysql>
1. 3 .主键索引
mysql> alter table user1 addprimary key(id);
Query OK, 2 rows affected (0.16 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> show create table user1\G;
Table: user1
Create Table: CREATE TABLE `user1` (
`id` int(11) NOT NULL DEFAULT '0',
`username` char(10) DEFAULT NULL,
`password` varchar(20) DEFAULTNULL,
`address` varchar(20) DEFAULTNULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_unique`(`username`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk
1 row in set (0.00 sec)
2 索引删除
删除唯一索引
mysql>alter table user1 drop index index_unique;
删除主键索引
第一种方法:
mysql> alter table user1 drop index primary key;
第二种方法:
mysql> drop index index_name on users;
3 复合索引
mysql> alter table user1 add index index_address_age(address,age);
Query OK, 0 rows affected (0.21 sec)
mysql> show create table user1\G;
Table: user1
Create Table: CREATE TABLE `user1` (
`id` int(11) NOT NULL DEFAULT '0',
`username` char(10) DEFAULT NULL,
`password` varchar(20) DEFAULTNULL,
`address` varchar(20) DEFAULTNULL,
`age` int(11) DEFAULT NULL,
KEY `index_address_age`(`address`,`age`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk
1 row in set (0.00 sec)
mysql>
4 索引查看
第一种方法:
mysql> show create table users\G;
第二种方法:
mysql> show index from users \G;
1.1 普通索引
1.2 .唯一索引
mysql> create UNIQUE index index_unique on user1(username);
mysql> show create table user1\G;
Table: user1
Create Table: CREATE TABLE `user1` (
`id` int(11) DEFAULT NULL,
`username` char(10) DEFAULT NULL,
`password` varchar(20) DEFAULTNULL,
`address` varchar(20) DEFAULTNULL,
UNIQUE KEY `index_unique`(`username`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk
1 row in set (0.00 sec)
mysql>
1. 3 .主键索引
mysql> alter table user1 addprimary key(id);
Query OK, 2 rows affected (0.16 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> show create table user1\G;
Table: user1
Create Table: CREATE TABLE `user1` (
`id` int(11) NOT NULL DEFAULT '0',
`username` char(10) DEFAULT NULL,
`password` varchar(20) DEFAULTNULL,
`address` varchar(20) DEFAULTNULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_unique`(`username`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk
1 row in set (0.00 sec)
2 索引删除
删除唯一索引
mysql>alter table user1 drop index index_unique;
删除主键索引
第一种方法:
mysql> alter table user1 drop index primary key;
第二种方法:
mysql> drop index index_name on users;
3 复合索引
mysql> alter table user1 add index index_address_age(address,age);
Query OK, 0 rows affected (0.21 sec)
mysql> show create table user1\G;
Table: user1
Create Table: CREATE TABLE `user1` (
`id` int(11) NOT NULL DEFAULT '0',
`username` char(10) DEFAULT NULL,
`password` varchar(20) DEFAULTNULL,
`address` varchar(20) DEFAULTNULL,
`age` int(11) DEFAULT NULL,
KEY `index_address_age`(`address`,`age`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk
1 row in set (0.00 sec)
mysql>
4 索引查看
第一种方法:
mysql> show create table users\G;
第二种方法:
mysql> show index from users \G;
相关文章推荐
- 网站之MySQL 索引分析和优化
- 详解mysql索引总结----mysql索引类型以及创建
- MySQL索引经验之浅见
- MySQL索引分析和优化
- 边学边用Mysql(2):索引的作用
- MySQL索引长度问题(转)
- mysql表锁、行锁、索引之间暧昧的关系
- 一个mysql表索引被破坏的问题及解决
- 通过实验分析索引对MySQL插入时性能的影响
- 加速动态网站 MySQL索引分析和优化
- MySQL索引经验之浅见
- MySQL索引分析和优化
- MYSQL 降序索引和减轻索引扫描
- MySql 函数索引
- MySQL查找的方式与索引的效率
- MySQL索引分析和优化
- MySQL索引分析和优化
- 在MySQL中创建索引
- Mysql建立索引,找出重复纪录,删除重复的纪录,ultraedit使用小技巧
- MySQL索引分析和优化