1、
Profiling 分析具體的sql語句消耗
MySQL5.0.37版本以上支持了Profiling –
官方手冊。此工具可用來查詢 SQL 會執(zhí)行多少時(shí)間, 并看出 CPU/Memory 使用量,執(zhí)行過程中 System lock和Table lock 花多少時(shí)間等等。從啟動profile之后的所有查詢包括錯(cuò)誤的語句都會記錄。關(guān)閉會話或者set profiling=0 就關(guān)閉。這對幫助排查和分析sql語句,還是比較有用的。
mysql> set profiling=1; #開啟mysql> select * from li limit 2;+--------+----------+| id | name |+--------+----------+| 1458 | hello |
| 1457 | world |
+--------+----------+mysql> show profiles;+--------------+----------------+------------------------------+| Query_ID | Duration | Query |+--------------+----------------+------------------------------+| 1 | 0.00013200 | SELECT DATABASE() |
| 2 | 0.00044100 | select * from li limit 2 |+--------------+----------------+------------------------------+mysql> show profile for query 2;+---------------------------+--------------+| Status | Duration |+---------------------------+--------------+| starting | 0.000058 |
| Opening tables | 0.000011 || System lock | 0.000007 || Table lock | 0.000014 || init | 0.000027 || optimizing | 0.000003 || statistics | 0.000010 || preparing | 0.000010 || executing | 0.000007 || Sending data | 0.000068 || end | 0.000003 || query end | 0.000002 || freeing items | 0.000208 || logging slow query | 0.000002 || logging slow query | 0.000009 || cleaning up | 0.000002 |+---------------------------+--------------+#此外還有2個(gè)語句可以查看更多信息。show profile cpu for query 2;show profile IPC for query 2;
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點(diǎn)擊舉報(bào)。