MySQL如何使用profiling

技术MySQL如何使用profiling这篇文章将为大家详细讲解有关MySQL如何使用profiling,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Mysql SQL优化工具我们常使

本文将详细解释如何在MySQL中为每个人使用概要分析。边肖觉得挺实用的,就分享给大家参考。希望你看完这篇文章能有所收获。

我们经常使用explain来分析sql的执行情况,并根据执行计划评估sql的性能消耗瓶颈,而Mysql sql Profiling则为我们提供了SQL执行过程中CPU/io/swap/内存的详细使用情况以及各个进程的执行时间消耗。主要用途为1:查看SQL执行消耗瓶颈位置2、查看sql的执行过程,每步操作在具体哪个源码文件的什么位置

下面简单介绍一下它的用法:

mysql 5.0.37之后支持性能分析,mysql5.7之后可以用performance_schema (25.18.1使用performance schema的查询性能分析)代替,但是通过会话级跟踪对1、相关变量更方便。

(root : localhost : wed 11月15日16:32:50 2017)[performance _ schema]显示像“%profil%”这样的变量;

- -

|变量名|值|

- -

| have_profiling | YES | ##是否支持profile函数?

| profiling | ON | ##是否打开配置文件,0|off表示关闭,1|on表示打开。

| profiling_history_size | 15 | ##默认情况下,显示的历史sql数量为最新的15个,最大值为100个。

-2.检查语法。

您可以通过帮助显示配置文件查看帮助文档。

Show profiles可以查看最近15次sql执行的历史记录。

单击(此处)折叠或打开。

显示配置文件[类型[,类型].]

[用于查询n]

[LIMIT row_count [OFFSET offset]]

:型

全部

|块输入输出

|上下文开关

|中央处理器

| IPC

| MEMORY

| PAGE FAULTS

| SOURCE

|互换

3、使用实例
1)开启profling
(root:localhost:Wed Nov 15 16:37:00 2017)[dbtest]> set profiling=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

(root:localhost:Wed Nov 15 16:37:14 2017)[dbtest]> show variables like '%profil%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| have_profiling         | YES   |
| profiling              | ON    |
| profiling_history_size | 15    |
+------------------------+-------+
3 rows in set (0.00 sec)
2)查看所有profiling记录的sql
(root:localhost:Wed Nov 15 16:37:16 2017)[dbtest]> show profiles;
+----------+------------+--------------------------------+
| Query_ID | Duration   | Query                          |
+----------+------------+--------------------------------+
|        1 | 0.00089900 | show variables like '%profil%' |
+----------+------------+--------------------------------+
3)查看指定profiling记录的sql
(root:localhost:Wed Nov 15 16:39:14 2017)[dbtest]> show profile for query 2 ;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000103 |
| checking permissions | 0.000008 |
| Opening tables       | 0.000060 |
| init                 | 0.000023 |
| System lock          | 0.000011 |
| optimizing           | 0.000007 |
| statistics           | 0.000016 |
| preparing            | 0.000015 |
| executing            | 0.000007 |
| Sending data         | 0.000063 |
| end                  | 0.000004 |
| query end            | 0.000010 |
| closing tables       | 0.000012 |
| freeing items        | 0.000016 |
| logging slow query   | 0.000003 |
| logging slow query   | 0.000070 |
| cleaning up          | 0.000014 |
+----------------------+----------+
4)查看指定profiling记录的sql,并且显示cpu/block io/的步骤消耗信息

(root:localhost:Wed Nov 15 16:43:47 2017)[dbtest]> show profile cpu ,block io for query 2;
+----------------------+----------+----------+------------+--------------+---------------+
| Status               | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting             | 0.000103 |     NULL |       NULL |         NULL |          NULL |
| checking permissions | 0.000008 |     NULL |       NULL |         NULL |          NULL |
| Opening tables       | 0.000060 |     NULL |       NULL |         NULL |          NULL |
| init                 | 0.000023 |     NULL |       NULL |         NULL |          NULL |
| System lock          | 0.000011 |     NULL |       NULL |         NULL |          NULL |
| optimizing           | 0.000007 |     NULL |       NULL |         NULL |          NULL |
| statistics           | 0.000016 |     NULL |       NULL |         NULL |          NULL |
| preparing            | 0.000015 |     NULL |       NULL |         NULL |          NULL |
| executing            | 0.000007 |     NULL |       NULL |         NULL |          NULL |
| Sending data         | 0.000063 |     NULL |       NULL |         NULL |          NULL |
| end                  | 0.000004 |     NULL |       NULL |         NULL |          NULL |
| query end            | 0.000010 |     NULL |       NULL |         NULL |          NULL |
| closing tables       | 0.000012 |     NULL |       NULL |         NULL |          NULL |
| freeing items        | 0.000016 |     NULL |       NULL |         NULL |          NULL |
| logging slow query   | 0.000003 |     NULL |       NULL |         NULL |          NULL |
| logging slow query   | 0.000070 |     NULL |       NULL |         NULL |          NULL |
| cleaning up          | 0.000014 |     NULL |       NULL |         NULL |          NULL |
+----------------------+----------+----------+------------+--------------+---------------+

5)查看指定profiling记录的sql,并且显示每步源码文件信息
(root:localhost:Wed Nov 15 16:44:09 2017)[dbtest]> show profile  source for query 2;
+----------------------+----------+-----------------------+------------------+-------------+
| Status               | Duration | Source_function       | Source_file      | Source_line |
+----------------------+----------+-----------------------+------------------+-------------+
| starting             | 0.000103 | NULL                  | NULL             |        NULL |
| checking permissions | 0.000008 | check_access          | sql_parse.cc     |        5635 |
| Opening tables       | 0.000060 | open_tables           | sql_base.cc      |        5029 |
| init                 | 0.000023 | mysql_prepare_select  | sql_select.cc    |        1051 |
| System lock          | 0.000011 | mysql_lock_tables     | lock.cc          |         304 |
| optimizing           | 0.000007 | optimize              | sql_optimizer.cc |         138 |
| statistics           | 0.000016 | optimize              | sql_optimizer.cc |         381 |
| preparing            | 0.000015 | optimize              | sql_optimizer.cc |         504 |
| executing            | 0.000007 | exec                  | sql_executor.cc  |         110 |
| Sending data         | 0.000063 | exec                  | sql_executor.cc  |         187 |
| end                  | 0.000004 | mysql_execute_select  | sql_select.cc    |        1106 |
| query end            | 0.000010 | mysql_execute_command | sql_parse.cc     |        5307 |
| closing tables       | 0.000012 | mysql_execute_command | sql_parse.cc     |        5383 |
| freeing items        | 0.000016 | mysql_parse           | sql_parse.cc     |        6676 |
| logging slow query   | 0.000003 | log_slow_do           | sql_parse.cc     |        2077 |
| logging slow query   | 0.000070 | log_slow_do           | sql_parse.cc     |        2078 |
| cleaning up          | 0.000014 | dispatch_command      | sql_parse.cc     |        1878 |
+----------------------+----------+-----------------------+------------------+-------------+
17 rows in set, 1 warning (0.00 sec)

6)查看指定profiling记录的sql,并且显示所有的步骤消耗信息

(root:localhost:Wed Nov 15 16:40:34 2017)[dbtest]> show profile all for query 2  \G
*************************** 1. row ***************************
             Status: starting
           Duration: 0.000103
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: NULL
        Source_file: NULL
        Source_line: NULL
*************************** 2. row ***************************
             Status: checking permissions
           Duration: 0.000008
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: check_access
        Source_file: sql_parse.cc
        Source_line: 5635
*************************** 3. row ***************************
             Status: Opening tables
           Duration: 0.000060
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: open_tables
        Source_file: sql_base.cc
        Source_line: 5029
*************************** 4. row ***************************
             Status: init
           Duration: 0.000023
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: mysql_prepare_select
        Source_file: sql_select.cc
        Source_line: 1051
*************************** 5. row ***************************
             Status: System lock
           Duration: 0.000011
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: mysql_lock_tables
        Source_file: lock.cc
        Source_line: 304
*************************** 6. row ***************************
             Status: optimizing
           Duration: 0.000007
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: optimize
        Source_file: sql_optimizer.cc
        Source_line: 138
*************************** 7. row ***************************
             Status: statistics
           Duration: 0.000016
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: optimize
        Source_file: sql_optimizer.cc
        Source_line: 381
*************************** 8. row ***************************
             Status: preparing
           Duration: 0.000015
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: optimize
        Source_file: sql_optimizer.cc
        Source_line: 504
*************************** 9. row ***************************
             Status: executing
           Duration: 0.000007
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: exec
        Source_file: sql_executor.cc
        Source_line: 110
*************************** 10. row ***************************
             Status: Sending data
           Duration: 0.000063
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: exec
        Source_file: sql_executor.cc
        Source_line: 187
*************************** 11. row ***************************
             Status: end
           Duration: 0.000004
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: mysql_execute_select
        Source_file: sql_select.cc
        Source_line: 1106
*************************** 12. row ***************************
             Status: query end
           Duration: 0.000010
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: mysql_execute_command
        Source_file: sql_parse.cc
        Source_line: 5307
*************************** 13. row ***************************
             Status: closing tables
           Duration: 0.000012
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: mysql_execute_command
        Source_file: sql_parse.cc
        Source_line: 5383
*************************** 14. row ***************************
             Status: freeing items
           Duration: 0.000016
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: mysql_parse
        Source_file: sql_parse.cc
        Source_line: 6676
*************************** 15. row ***************************
             Status: logging slow query
           Duration: 0.000003
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: log_slow_do
        Source_file: sql_parse.cc
        Source_line: 2077
*************************** 16. row ***************************
             Status: logging slow query
           Duration: 0.000070
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: log_slow_do
        Source_file: sql_parse.cc
        Source_line: 2078
*************************** 17. row ***************************
             Status: cleaning up
           Duration: 0.000014
           CPU_user: NULL
         CPU_system: NULL
  Context_voluntary: NULL
Context_involuntary: NULL
       Block_ops_in: NULL
      Block_ops_out: NULL
      Messages_sent: NULL
  Messages_received: NULL
  Page_faults_major: NULL
  Page_faults_minor: NULL
              Swaps: NULL
    Source_function: dispatch_command
        Source_file: sql_parse.cc
        Source_line: 1878
17 rows in set, 1 warning (0.00 sec)

关于“MySQL如何使用profiling”这篇文章就分享到这里了,希望

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/66414.html

(0)

相关推荐

  • 四时田园杂兴题目意思,四时田园杂兴的全部意思

    技术四时田园杂兴题目意思,四时田园杂兴的全部意思四时田园杂兴古诗的意思是:一树树梅子变得金黄,杏子也越长越大了;荞麦花一片雪白,油菜花倒显得稀稀落落四时田园杂兴题目意思。白天长了,篱笆的影子随着太阳的升高变得越来越短,没

    生活 2021年10月23日
  • ace什么意思,女团中的ACE是什么意思

    技术ace什么意思,女团中的ACE是什么意思ACE不知道吗?没玩过英雄联盟和王者荣耀吗,还是你们从来没有ACE过对面,而放到女团中,就是能把队友团灭的人ace什么意思。而换一种说法就是,对团队做出的贡献最大,并且拥有最大

    生活 2021年10月30日
  • 怎么使用css伪元素before和after

    技术怎么使用css伪元素before和after这篇文章主要讲解了“怎么使用css伪元素before和after”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么使用cs

    攻略 2021年11月15日
  • 社保局什么时候上班,社保局几点上班

    技术社保局什么时候上班,社保局几点上班上午11:30和下午5:30 社保局什么时候上班。社会保险 (Social Insurance) 是一种为丧失劳动能力、暂时失去劳动岗位或因健康原因造成损失的人口提供收入或补偿的一种

    生活 2021年10月26日
  • 现代云架构中的AWS服务器群和数据库是怎么样的

    技术现代云架构中的AWS服务器群和数据库是怎么样的这篇文章给大家介绍现代云架构中的AWS服务器群和数据库是怎么样的,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。当今云计算技术成了主流的架构和互联网基

    攻略 2021年12月2日
  • css3变形效果好吗(css3中2d变形类型有哪些)

    技术CSS3变形技术有哪些本篇内容介绍了“CSS3变形技术有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

    攻略 2021年12月15日