mysql show profile_show profiles 查看MySQL语句的执行时间

show profiles

作用范围

这个命令只是在本会话内起作用,即无法分析本会话外的语句。

开启分析功能后,所有本会话中的语句都被分析(甚至包括执行错误的语句),除了SHOW PROFILE和SHOW PROFILES两句本身。

方法一:profiling

mysql>  show variables like "profiling";

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| profiling     | OFF   |

+---------------+-------+

1 row in set (0.01 sec)

mysql> set profiling = 1;

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

mysql> select user,authentication_string,host from mysql.user;

5 rows in set (0.00 sec)

mysql> show profile for query 1;

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000069 |

| checking permissions | 0.000008 |

| Opening tables       | 0.000109 |

| init                 | 0.000018 |

| System lock          | 0.000009 |

| optimizing           | 0.000003 |

| statistics           | 0.000014 |

| preparing            | 0.000010 |

| executing            | 0.000003 |

| Sending data         | 0.000038 |

| end                  | 0.000004 |

| query end            | 0.000005 |

| closing tables       | 0.000007 |

| freeing items        | 0.000011 |

| cleaning up          | 0.000013 |

+----------------------+----------+

15 rows in set, 1 warning (0.01 sec)

mysql> show profile cpu, block io, memory,swaps,context switches,source for query 1;

+----------------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+-------+-----------------------+----------------------+-------------+

| Status               | Duration | CPU_user | CPU_system | Context_voluntary | Context_involuntary | Block_ops_in | Block_ops_out | Swaps | Source_function       | Source_file          | Source_line |

+----------------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+-------+-----------------------+----------------------+-------------+

| starting             | 0.000069 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | NULL                  | NULL                 |        NULL |

| checking permissions | 0.000008 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | check_access          | sql_authorization.cc |         810 |

| Opening tables       | 0.000109 | 0.001000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | open_tables           | sql_base.cc          |        5650 |

| init                 | 0.000018 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | handle_query          | sql_select.cc        |         121 |

| System lock          | 0.000009 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | mysql_lock_tables     | lock.cc              |         323 |

| optimizing           | 0.000003 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | optimize              | sql_optimizer.cc     |         151 |

| statistics           | 0.000014 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | optimize              | sql_optimizer.cc     |         367 |

| preparing            | 0.000010 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | optimize              | sql_optimizer.cc     |         475 |

| executing            | 0.000003 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | exec                  | sql_executor.cc      |         119 |

| Sending data         | 0.000038 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | exec                  | sql_executor.cc      |         195 |

| end                  | 0.000004 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | handle_query          | sql_select.cc        |         199 |

| query end            | 0.000005 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | mysql_execute_command | sql_parse.cc         |        4968 |

| closing tables       | 0.000007 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | mysql_execute_command | sql_parse.cc         |        5020 |

| freeing items        | 0.000011 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | mysql_parse           | sql_parse.cc         |        5596 |

| cleaning up          | 0.000013 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | dispatch_command      | sql_parse.cc         |        1902 |

+----------------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+-------+-----------------------+----------------------+-------------+

15 rows in set, 1 warning (0.00 sec)

mysql>  select * from employees.employees where emp_no=10001;

+--------+------------+------------+-----------+--------+------------+

| emp_no | birth_date | first_name | last_name | gender | hire_date  |

+--------+------------+------------+-----------+--------+------------+

|  10001 | 1953-09-02 | Georgi     | Facello   | M      | 1986-06-26 |

+--------+------------+------------+-----------+--------+------------+

1 row in set (0.00 sec)

mysql> show profile cpu, block io, memory,swaps,context switches,source for query 2;

+---------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+-------+------------------+--------------+-------------+

| Status        | Duration | CPU_user | CPU_system | Context_voluntary | Context_involuntary | Block_ops_in | Block_ops_out | Swaps | Source_function  | Source_file  | Source_line |

+---------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+-------+------------------+--------------+-------------+

| starting      | 0.000083 | 0.000000 |   0.001000 |                 0 |                   0 |            0 |             0 |     0 | NULL             | NULL         |        NULL |

| freeing items | 0.000016 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | mysql_parse      | sql_parse.cc |        5596 |

| cleaning up   | 0.000005 | 0.000000 |   0.000000 |                 0 |                   0 |            0 |             0 |     0 | dispatch_command | sql_parse.cc |        1902 |

+---------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+-------+------------------+--------------+-------------+

3 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 2;

+---------------+----------+

| Status        | Duration |

+---------------+----------+

| starting      | 0.000083 |

| freeing items | 0.000016 |

| cleaning up   | 0.000005 |

+---------------+----------+

3 rows in set, 1 warning (0.01 sec)

mysql>  set profiling=0 ;

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

方法二:timestampdiff来查看执行时间。

mysql>

set @d=now();

select * from employees.employees where emp_no=10001;

select timestampdiff(second,@d,now());

--回车

+--------------------------------+

| timestampdiff(second,@d,now()) |

+--------------------------------+

|                             21 |

+--------------------------------+

1 row in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值