mysql数据库如何创建索引
/*
Navicat MySQL Data Transfer
Source Server : 测试
Source Server Version : 50709
Source Host : 192.168.1.108:3306
Source Database : test2
Target Server Type : MYSQL
Target Server Version : 50709
File Encoding : 65001
Date: 2017-06-26 17:56:54
*/
SET FOREIGN_KEY_CHECKS=0;
-- Table / for city
DROP TABLE IF EXISTS city
;
CREATE TABLE city
(id
int(11) NOT NULL AUTO_INCREMENT,country
varchar(255) DEFAULT NULL,name
varchar(255) DEFAULT NULL,state
varchar(255) DEFAULT NULL,code_name
varchar(255) DEFAULT NULL,
PRIMARY KEY (id
),
KEY index_id
(id
) USING BTREE,
KEY index_name
(name
),
KEY index_mass
(country
,name
),
FULLTEXT KEY country
(country
)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
普通索引
ALTER TABLE city ADD INDEX index_name (name);
主键索引
ALTER TABLE city ADD PRIMARY KEY (id);
全文索引
ALTER TABLE city ADD FULLTEXT (country);
多列索引
ALTER TABLE city ADD INDEX index_mass (country,name);
最后更新:2017-06-26 18:02:41