# Linux: /etc/my.cnf # Windows: my.ini [mysqld] log-slow-queries = /tmp/mysql-slow.log long_query_time = 2
Time: 120815 23:22:11 User@Host: root[root] @ localhost [] Query_time: 9.869362 Lock_time: 0.000035 Rows_sent: 1 Rows_examined: 6261774 SET timestamp=1294388531; select count(*) from blog;
| 字段 | 含義 | 優化意義 |
|---|---|---|
| Query_time | SQL 執行總耗時 | 核心指標,越長越需優化 |
| Lock_time | Server 層表鎖等待 | 高則檢查鎖爭用 |
| Rows_sent | 返回行數 | 對比 Rows_examined 判斷索引效率 |
| Rows_examined | 實際掃描行數 | 遠大於 Sent 說明全表掃描 |
tail -f /tmp/mysql-slow.log
-s -t -g 快速定位 Top 慢查詢pt-query-digest /tmp/mysql-slow.log --limit 20 --filter '$event->{Query_time} > 1'
輸出含:指紋、執行次數、總耗時、平均耗時、Rows examined、完整 SQL 樣本,較 mysqldumpslow 更強大。