1. 程式人生 > 其它 >MySQL索引相關

MySQL索引相關

MySQL新增索引:

  

-- 使用某資料庫 scheam
use ua;

show tables;
-- 查看錶結構
desc ua.log;
-- 檢視索引
show index from ua.log;

-- 新增組合索引
ALTER TABLE `log` ADD INDEX index_log_type ( `log_type`, `op_type`, `is_deleted`,`created_dt`);
ALTER TABLE `log` ADD INDEX index_op_type ( `op_type`, `log_type`, `is_deleted`,`created_dt`);

-- 刪除索引
alter table `ua`.`log` drop index index_op_type;
-- drop index index_name on table_name ;
-- alter table table_name drop index index_name ;
-- alter table table_name drop primary key ;

-- 新增單列索引
ALTER TABLE `log` ADD INDEX index_op_type (`op_type`);

-- 新增主鍵索引
alter table `log` add primary key (`id`);
-- 新增唯一索引
alter table `ua`.`log` add unique (`id`);

-- 新增普通索引
alter table `ua`.`log` add index index_opt_type (`op_type`);

-- 新增全文索引
alter table `ua`.`log` add fulltext full_remark (`remark`);

-- 新增多列索引或者組合索引
alter table `ua`.`log` add index index_op_type ( `op_type`, `log_type`, `is_deleted`,`created_dt`);

主鍵索引&唯一索引&組合索引&普通索引 設定索引型別BTREE

全文索引 設定索引型別 FULLTEXT