一些常用的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的执行情况。