mysql查詢語句優化工具
把這個profiling功能開啟,可以檢視sql查詢語句的整個過程中各種資源的消耗情況。
mysql> show profiles;
+----------+------------+---------------------------------+
| Query_ID | Duration | Query |
+----------+------------+---------------------------------+
| 1 | 0.00049600 | show variables like "profiling" |
| 2 | 0.02267400 | show databases |
| 3 | 0.04235200 | SELECT DATABASE() |
| 4 | 0.00012825 | SELECT DATABASE() |
| 5 | 0.00025125 | show databases |
| 6 | 0.00145125 | show tables |
| 7 | 0.04207925 | show tables |
| 8 | 0.03485225 | select count(*) from host_item |
+----------+------------+---------------------------------+
mysql> show profile cpu, block io for query 8;
+----------------------+----------+----------+------------+--------------+---------------+
| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting | 0.000634 | 0.000000 | 0.000000 | 0 | 0 |
| checking permissions | 0.000013 | 0.000000 | 0.000000 | 0 | 0 |
| Opening tables | 0.000051 | 0.000000 | 0.000000 | 0 | 0 |
| System lock | 0.000014 | 0.000000 | 0.000000 | 0 | 0 |
| init | 0.000015 | 0.000000 | 0.000000 | 0 | 0 |
| optimizing | 0.033657 | 0.000000 | 0.000000 | 40 | 0 |
| statistics | 0.000029 | 0.000000 | 0.000000 | 0 | 0 |
| preparing | 0.000012 | 0.000000 | 0.000000 | 0 | 0 |
| executing | 0.000006 | 0.000000 | 0.000000 | 0 | 0 |
| Sending data | 0.000313 | 0.000000 | 0.000000 | 0 | 0 |
| end | 0.000008 | 0.000000 | 0.000000 | 0 | 0 |
| query end | 0.000008 | 0.000000 | 0.000000 | 0 | 0 |
| closing tables | 0.000047 | 0.000000 | 0.000000 | 0 | 0 |
| freeing items | 0.000042 | 0.000000 | 0.000000 | 0 | 0 |
| logging slow query | 0.000003 | 0.000000 | 0.000000 | 0 | 0 |
| cleaning up | 0.000003 | 0.000000 | 0.000000 | 0 | 0 |
+----------------------+----------+----------+------------+--------------+---------------
show profile後面可以跟引數:all或者cpu,block io,page faults等。
也可以在information_schema.profiling資料庫表中直接查詢:
select state,sum(duration) as total_r,round(100*sum(duration)/(select sum(duration) from information_schema.profiling where query_id=@query_id),2) as pct_r,count(*) as calls,sum(duration)/count(*) as "r/call" from information_schema.profiling where query_id=@query_id group by state order by total_r desc;
最後,關閉set profiling=0該功能。
本文轉自chenzudao51CTO部落格,原文連結: http://blog.51cto.com/victor2016/1875012,如需轉載請自行聯絡原作者
相關文章
- 效能優化查詢語句優化
- 《MySQL慢查詢優化》之SQL語句及索引優化MySql優化索引
- MySql常用30種SQL查詢語句優化方法MySql優化
- mysql查詢語句MySql
- [Mysql 查詢語句]——查詢欄位MySql
- mysql查詢語句集MySql
- MySQL查詢阻塞語句MySql
- Mysql之查詢語句MySql
- mysql查詢語句5:連線查詢MySql
- [Mysql 查詢語句]——分組查詢group byMySql
- [Mysql 查詢語句]——查詢指定記錄MySql
- Sql語句本身的優化-定位慢查詢SQL優化
- 一個connect by查詢語句的優化優化
- mysql高階查詢語句MySql
- MySQL基礎查詢語句MySql
- 淺談MySQL中優化sql語句查詢常用的30種方法MySql優化
- MySQL查詢優化MySql優化
- MYSQL SQL語句優化MySql優化
- MySQL——優化ORDER BY語句MySql優化
- mysql limit語句優化MySqlMIT優化
- mysql 優化常用語句MySql優化
- PostgreSQL 原始碼解讀(29)- 查詢語句#14(查詢優化-上拉子查詢)SQL原始碼優化
- MySQL內連線查詢語句MySql
- MySQL的簡單查詢語句MySql
- mysql dba常用的查詢語句MySql
- [Mysql 查詢語句]——集合函式MySql函式
- mysql 查詢建表語句sqlMySql
- PostgreSQL 原始碼解讀(25)- 查詢語句#10(查詢優化概覽)SQL原始碼優化
- PostgreSQL 原始碼解讀(17)- 查詢語句#2(查詢優化基礎)SQL原始碼優化
- MySQL 的查詢優化MySql優化
- MySQL 慢查詢優化MySql優化
- MySQL優化COUNT()查詢MySql優化
- 資料庫設計與查詢語句的優化資料庫優化
- 【效能優化】查詢繫結變數的sql語句優化變數SQL
- ORACLE結構化查詢語句Oracle
- MySQL之SQL語句優化MySql優化
- mysql查詢優化檢查 explainMySql優化AI
- MySQL調優之查詢優化MySql優化