一些常用的MySQL索引及Profiling小知識,
一,查看某個表的索引
mysql > show indexes from [tablename] \G Table: album Non_unique: 0 Key_name: PRIMARY Seq_in_index: 1 Column_name: album_id Collation: A Cardinality: 29 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: 二,強制索引
mysql > select * from [tablename] force index([indexname]) where [xxxx] 三,創建索引
mysql > create index [index_name] on [tablename] ([index]); 四,刪除索引
mysql > drop index [index_name] on [tablename]; 索引的好壞直接影響到MySQL數據庫的執行性能,可結合Explain和Profiling工具進行檢查。
Profiling使用方法如下:
mysql > set profiling = 1; mysql > select * from [tablename] mysql > show profiles; mysql > show profile [cpu, block] io for query [xx]; 掌握profiling檢查MySQL的執行情況。