explain select * from test1 where id=1;
id selecttype table type possible_keys key key_len ref rows extra
假设表有id,key1,key2,key3,把三者造成一个组合索引,则html
如:mysql
where key1=.... where key1=1 and key2=2 where key1=3 and key3=3 and key2=2sql
如性能
from test where key1=1 order by key3
三、使用慢查询分析:spa
在my.ini中:日志
long_query_time=1 log-slow-queries=d:\mysql5\logs\mysqlslow.log
把超过1秒的记录在慢查询日志中code
能够用mysqlsla来分析之。也能够在mysqlreport中,有如DMS分别分析了select,update,insert,delete,replace等所占的百份比orm
四、MyISAM和InnoDB的锁定htm
MyISAM中,注意是表锁来的,好比在多个update操做后,再select时,会发现select操做被锁定了,必须等全部update操做完毕后,再能select blog
InnoDB的话则不一样了,用的是行锁,不存在上面问题。
五、MySQL的事务配置项
innodb_flush_log_at_trx_commit=1
innodb_flush_log_at_trx_commit=0
innodb_flush_log_at_trx_commit=2
六、explain用法
explain tbl_name 或: explain [extended] select select_options
explain select * from event;
+—-+————-+——-+——+—————+——+———+——+——+——-+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +—-+————-+——-+——+—————+——+———+——+——+——-+ | 1 | SIMPLE | event | ALL | NULL | NULL | NULL | NULL | 13 | | +—-+————-+——-+——+—————+——+———+——+——+——-+ 1 row in set (0.00 sec)
参考:
http://blog.sina.com.cn/s/blog_4586764e0100o9s1.html(以上内容转自此篇文章)