建立索引加快查询速度:select * from t_user1 where username='测试'
1.创建表时建立索引
1)普通索引
CREATE TABLE t_user1(
id INT PRIMARY KEY AUTO_INCREMENT ,
username VARCHAR(20),
PASSWORD VARCHAR(20),
INDEX (username)
);
2)唯一索引,并为索引起别名
CREATE TABLE t_user2 (
id INT PRIMARY KEY AUTO_INCREMENT ,
username VARCHAR(20),
PASSWORD VARCHAR(20),
UNIQUE INDEX index_username ( username)
);
3)多列索引
CREATE TABLE t_user3 (
id INT PRIMARY KEY AUTO_INCREMENT ,
username VARCHAR(20),
PASSWORD VARCHAR(20),
INDEX index_username_password(username,PASSWORD)
);