mysql索引
来源:互联网 发布:淘宝橱窗推荐怎么设置 编辑:程序博客网 时间:2024/06/01 07:57
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;
- MySQL索引 聚集索引
- mysql 索引 & 索引类型
- MySQL索引 聚集索引
- mysql 索引 & 索引类型
- mysql索引
- mysql索引
- mysql 索引
- MySql索引
- Mysql索引
- mysql 索引
- mysql 索引
- MySQL索引
- mysql索引
- mysql 索引
- mysql索引
- mysql 索引
- MySQL索引
- mysql索引
- 应用ROWDEPENDENCIES行级跟踪,查询…
- Oracle使用对象类型7(自定义…
- 图解文玩核桃的种类和特点
- ORACLE中如何查看分区表信息
- RMAN命令详解
- mysql索引
- MariaDB Galera C…
- binlog,redo log,undo log区别
- android--如何将View转换成Bitmap
- RMAN基于时间点恢复不完全恢…
- 实战体验几种MySQLCluster方…
- MySQL】5.7版本 Semisy…
- MHA自动Failover过程解析(up…
- MySQL 5.7 并行复…