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(以上內容轉自此篇文章)