99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

MySQL性能分析工具之PROFILE怎么用

小編給大家分享一下MySQL性能分析工具之PROFILE怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創新互聯致力于做網站、成都網站制作,成都網站設計,集團網站建設等服務標準化,推過標準化降低中小企業的建站的成本,并持續提升建站的定制化服務水平進行質量交付,讓企業網站從市場競爭中脫穎而出。 選擇創新互聯,就選擇了安全、穩定、美觀的網站建設服務!

分析SQL執行帶來的開銷是優化SQL的常用手段,在MySQL數據庫中,可以通過配置profiling參數來啟用SQL剖析。
它只能在session級別來設置,設置后影響當前session;當它開啟后,后續執行的SQL語句都將記錄其資源開銷,諸如IO,上下文,CPU,MEMORY等。

實驗環境:

  1. mysql> select version();

  2. +------------+

  3. | version() |

  4. +------------+

  5. | 5.7.17-log |

  6. +------------+

  7. 1 row in set (0.00 sec)

與profile相關的三個參數:

  1. mysql> show variables like '%profil%';

  2. +------------------------+-------+

  3. | Variable_name | Value |

  4. +------------------------+-------+

  5. | have_profiling | YES |                  ---用于控制是否由系統變量開啟或禁用profiling

  6. | profiling | OFF |                       ---開啟SQL語句剖析功能

  7. | profiling_history_size | 15 |           ---設置保留profiling的數目,缺省為15,范圍為0至100,為0時將禁用profiling

  8. +------------------------+-------+

  9. 3 rows in set (0.01 sec)

開啟profiling,有個警告,這個參數在以后會被刪除,用information_scheam.PROFILING替代。

  1. mysql> set profiling=1;

  2. Query OK, 0 rows affected, 1 warning (0.00 sec)

  3. mysql> show warnings;
    +---------+------+----------------------------------------------------------------------+
    | Level   | Code | Message                                                              |
    +---------+------+----------------------------------------------------------------------+
    | Warning | 1287 | '@@profiling' is deprecated and will be removed in a future release. |
    +---------+------+----------------------------------------------------------------------+

執行一條sql測試一下:

  1. select * from oms3.customers where `type` = 1 AND `status` < 7 AND `isarea` = 6 AND `into_time`>='2016-12-01'AND `into_time`<='2017-01-02 23:59:59' order by score desc limit 40,20

sql執行很慢,執行完成之后查看:

  1. mysql> show profiles;

  2. +----------+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

  3. | Query_ID | Duration | Query |

  4. +----------+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

  5. | 7 | 0.00022275 | SELECT * FROM setup_actors |

  6. | 8 | 0.00016050 | SELECT DATABASE() |

  7. | 9 | 0.00032350 | show databases |

  8. | 10 | 0.00024050 | show tables |

  9. | 11 | 0.00019250 | SELECT * FROM setup_actors |

  10. | 12 | 0.00183950 | show variables like "profiling_hist%" |

  11. | 13 | 0.00192500 | show variables like '%profil%' |

  12. | 14 | 0.00011550 | show warnings |

  13. | 15 | 0.00044725 | help 'show profile' |

  14. | 16 | 0.00013875 | set profiling=1 |

  15. | 17 | 0.00011550 | show warnings |

  16. | 18 | 0.00025075 | select * from customers where `type` = 1 AND `status` < 7 AND `isarea` = 6 AND `into_time`>='2016-12-01'AND `into_time`<='2017-01-02 23:59:59' order by score desc limit 40,20 |

  17. | 19 | 333.19133875 | select * from oms3.customers where `type` = 1 AND `status` < 7 AND `isarea` = 6 AND `into_time`>='2016-12-01'AND `into_time`<='2017-01-02 23:59:59' order by score desc limit 40,20 |

  18. | 20 | 0.00011250 | show profilings |

  19. | 21 | 0.00010975 | show profilings |

  20. +----------+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

  21. 15 rows in set, 1 warning (0.00 sec)

  22. mysql> set @query_id=19;                ---上面顯示是query_id為19

  23. Query OK, 0 rows affected (0.00 sec)

  24. mysql> select STATE,sum(duration) as Total_R,          ---用這條sql查詢具體是哪里出問題,這條sql引用于《High Performance MySQL,Third Edition》

  25.     -> ROUND(

  26.     -> 100*SUM(DURATION)/

  27.     -> (SELECT SUM(DURATION) FROM INFORMATiON_SCHEMA.PROFILING WHERE QUERY_ID=@query_id),2) as Pct_R,

  28.     -> count(*) as calls,

  29.     -> sum(duration)/count(*) as "R/Call"

  30.     -> from information_schema.profiling

  31.     -> where query_id=@query_id

  32.     -> group by state

  33.     -> order by Total_R desc;

  34. +----------------------+------------+-------+-------+----------------+

  35. | STATE | Total_R | Pct_R | calls | R/Call |

  36. +----------------------+------------+-------+-------+----------------+

  37. | Sending data | 332.162424 | 99.69 | 1 | 332.1624240000 |         ---這個state基本占用了全部的資源,那么對這條sql的優化就著重于減少io上。

  38. | statistics | 1.027729 | 0.31 | 1 | 1.0277290000 |

  39. | Opening tables | 0.000519 | 0.00 | 1 | 0.0005190000 |

  40. | freeing items | 0.000157 | 0.00 | 1 | 0.0001570000 |

  41. | starting | 0.000147 | 0.00 | 1 | 0.0001470000 |

  42. | init | 0.000123 | 0.00 | 1 | 0.0001230000 |

  43. | logging slow query | 0.000096 | 0.00 | 1 | 0.0000960000 |

  44. | preparing | 0.000035 | 0.00 | 1 | 0.0000350000 |

  45. | cleaning up | 0.000019 | 0.00 | 1 | 0.0000190000 |

  46. | optimizing | 0.000016 | 0.00 | 1 | 0.0000160000 |

  47. | end | 0.000014 | 0.00 | 1 | 0.0000140000 |

  48. | System lock | 0.000014 | 0.00 | 1 | 0.0000140000 |

  49. | closing tables | 0.000013 | 0.00 | 1 | 0.0000130000 |

  50. | query end | 0.000013 | 0.00 | 1 | 0.0000130000 |

  51. | Sorting result | 0.000010 | 0.00 | 1 | 0.0000100000 |

  52. | checking permissions | 0.000009 | 0.00 | 1 | 0.0000090000 |

  53. | executing | 0.000003 | 0.00 | 1 | 0.0000030000 |

  54. +----------------------+------------+-------+-------+----------------+

  55. 17 rows in set, 18 warnings (0.00 sec)

其他用法:

  1. mysql> SHOW PROFILE CPU FOR QUERY 2;

  2. +----------------------+----------+----------+------------+

  3. | Status | Duration | CPU_user | CPU_system |

  4. +----------------------+----------+----------+------------+

  5. | checking permissions | 0.000040 | 0.000038 | 0.000002 |

  6. | creating table | 0.000056 | 0.000028 | 0.000028 |

  7. | After create | 0.011363 | 0.000217 | 0.001571 |

  8. | query end | 0.000375 | 0.000013 | 0.000028 |

  9. | freeing items | 0.000089 | 0.000010 | 0.000014 |

  10. | logging slow query | 0.000019 | 0.000009 | 0.000010 |

  11. | cleaning up | 0.000005 | 0.000003 | 0.000002 |

  12. +----------------------+----------+----------+------------+

更多用法詳見:

help show profiles;

以上是“MySQL性能分析工具之PROFILE怎么用”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯行業資訊頻道!

本文題目:MySQL性能分析工具之PROFILE怎么用
本文路徑:http://www.yijiale78.com/article30/jjpdpo.html

成都網站建設公司_創新互聯,為您提供小程序開發域名注冊手機網站建設建站公司營銷型網站建設用戶體驗

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都做網站