MySQL select,mysql query profiler_MySQL Query Profiler

 2023-10-24 阅读 31 评论 0

摘要:查看MySQL語法詳細執行時間與CPU/記憶體使用量: MySQL Query ProfilerMySQL的SQL語法調整主要都是使用EXPLAIN,但是這個并沒辦法知道詳細的Ram(Memory)/CPU等使用量.于MySQL 5.0.37以上開始支援MySQL Query Profiler,可以查詢到此SQL會執行多少時間,并看出CPU/Memory使用量,執

查看MySQL語法詳細執行時間與CPU/記憶體使用量: MySQL Query Profiler

MySQL的SQL語法調整主要都是使用EXPLAIN,但是這個并沒辦法知道詳細的Ram(Memory)/CPU等使用量.于MySQL 5.0.37以上開始支援MySQL Query Profiler,可以查詢到此SQL會執行多少時間,并看出CPU/Memory使用量,執行過程中System lock, Table lock花多少時間等等.

MySQL Query Profile詳細介紹可見: Using the New MySQL Query Profiler (2007.04.05發表)效能分析主要分下述三種(轉載自上篇):

? Bottleneck analysis - focuses on answering the questions: What is my database server waiting on; what is a user connection waiting on; what is a piece of SQL code waiting on?

MySQL select,? Workload analysis - examines the server and who is logged on to determine the resource usage and activity of each.

? Ratio-based analysis - utilizes a number of rule-of-thumb ratios to gauge performance of a database, user connection, or piece of code.

MySQL Query Profile使用方法啟動? mysql> set profiling=1;#此命令于MySQL會于information_schema的database建立一個PROFILING的table來紀錄.

SQL profiles show

? mysql> show profiles; #從啟動之后所有語法及使用時間,含錯誤語法都會紀錄.

php—mysql?? ex: (root@localhost) [test]> show profiles; #注意Query_ID,下面執行時間統計等,都是依Query_ID在紀錄? +----------+------------+------------------------ ---+

? | Query_ID | Duration | Query |

? +----------+------------+------------------------ ---+

? | 1 | 0.00090400 | show profile for query 1 |

? | 2 | 0.00008700 | select * from users |

sqlquery函數?? | 3 | 0.00183800 | show tables |

? | 4 | 0.00027600 | mysql> show profiles |

? +----------+------------+------------------------ ---+查詢所有花費時間加總? mysql> select sum(duration) from information_schema.profiling where query_id=1; # Query ID = 1

? +---------------+

? | sum(duration) |

mysql常用api、? +---------------+

? | 0.000447 |

? +---------------+查詢各執行階段花費多少時間? mysql> show profile for query 1; # Query ID = 1

? +--------------------+------------+

? | Status | Duration |

mysql varchar?? +--------------------+------------+

? | (initialization) | 0.00006300 |

? | Opening tables | 0.00001400 |

? | System lock | 0.00000600 |

? | Table lock | 0.00001000 |

MySQL source?? | init | 0.00002200 |

? | optimizing | 0.00001100 |

? | statistics | 0.00009300 |

? | preparing | 0.00001700 |

? | executing | 0.00000700 |

MySQL shell。? | Sending data | 0.00016800 |

? | end | 0.00000700 |

? | query end | 0.00000500 |

? | freeing items | 0.00001200 |

? | closing tables | 0.00000800 |

mysql里、? | logging slow query | 0.00000400 |

? +--------------------+------------+查詢各執行階段花費的各種資源列表? mysql> show profile cpu for query 1; # Query ID = 1

? +--------------------------------+----------+---- ------+------------+

? | Status | Duration | CPU_user | CPU_system |

? +--------------------------------+----------+---- ------+------------+

sqlquery工具。? | (initialization) | 0.000007 | 0 | 0 |

? | checking query cache for query | 0.000071 | 0 | 0 |

? | Opening tables | 0.000024 | 0 | 0 |

? | System lock | 0.000014 | 0 | 0 |

? | Table lock | 0.000055 | 0.001 | 0 |

php和mysql關系、? | init | 0.000036 | 0 | 0 |

? | optimizing | 0.000013 | 0 | 0 |

? | statistics | 0.000021 | 0 | 0 |

? | preparing | 0.00002 | 0 | 0 |

? | executing | 0.00001 | 0 | 0 |

mysql_query創建數據庫?? | Sending data | 0.015072 | 0.011998 | 0 |

? | end | 0.000021 | 0 | 0 |

? | query end | 0.000011 | 0 | 0 |

? | storing result in query cache | 0.00001 | 0 | 0 |

? | freeing items | 0.000018 | 0 | 0 |

SQLQuery。? | closing tables | 0.000019 | 0 | 0 |

? | logging slow query | 0.000009 | 0 | 0 |

? +--------------------------------+----------+---- ------+------------+

? mysql> show profile IPC for query 1;

? +--------------------------------+----------+---- -----------+-------------------+

MySQL 查詢,? | Status | Duration | Messages_sent | Messages_received |

? +--------------------------------+----------+---- -----------+-------------------+

? | (initialization) | 0.000007 | 0 | 0 |

? | checking query cache for query | 0.000071 | 0 | 0 |

? | Opening tables | 0.000024 | 0 | 0 |

? | System lock | 0.000014 | 0 | 0 |

? | Table lock | 0.000055 | 0 | 0 |

? | init | 0.000036 | 0 | 0 |

? | optimizing | 0.000013 | 0 | 0 |

? | statistics | 0.000021 | 0 | 0 |

? | preparing | 0.00002 | 0 | 0 |

? | executing | 0.00001 | 0 | 0 |

? | Sending data | 0.015072 | 0 | 0 |

? | end | 0.000021 | 0 | 0 |

? | query end | 0.000011 | 0 | 0 |

? | storing result in query cache | 0.00001 | 0 | 0 |

? | freeing items | 0.000018 | 0 | 0 |

? | closing tables | 0.000019 | 0 | 0 |

? | logging slow query | 0.000009 | 0 | 0 |

? +--------------------------------+----------+---- -----------+-------------------+其它屬性列表? ALL - displays all information

? BLOCK IO - displays counts for block input and output operations

? CONTEXT SWITCHES - displays counts for voluntary and involuntary context switches

? IPC - displays counts for messages sent and received

? MEMORY - is not currently implemented

? PAGE FAULTS - displays counts for major and minor page faults

? SOURCE - displays the names of functions from the source code, together with the name and line number of the file in which the function occurs

? SWAPS - displays swap counts設定Profiling存的Size

? mysql> show variables where variable_name='profiling_history_size'; #預設是15關閉? mysql> set profiling=0;

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/163601.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息