博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql忧化查看工具之profile
阅读量:5940 次
发布时间:2019-06-19

本文共 5801 字,大约阅读时间需要 19 分钟。

  mysql可以用自带的profile功能查看执行语句需要哪些系统资源,比如cpu,内存,磁盘io之类的,功能默认是关闭状态需手动开启,profile对管理或者开发dba都有很大的帮助.

mysql dba技术群 378190849

武汉-linux运维群 236415619

1.查看profile功能的状态

[root@tong1 ~]# /usr/local/mysql-5.6.23/bin/mysql -u root -p

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5499
Server version: 5.6.23-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like '%pro%';
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| have_profiling            | YES   |
profiling                 | OFF   |     --默认是关闭状态
| profiling_history_size    | 15    |
| protocol_version          | 10    |
| proxy_user                |       |
| slave_compressed_protocol | OFF   |
| stored_program_cache      | 256   |
+---------------------------+-------+
7 rows in set (0.00 sec)
mysql> set @@profiling=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show variables like '%profiling%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| have_profiling         | YES   |
profiling              | ON    |
| profiling_history_size | 15    |
+------------------------+-------+
3 rows in set (0.00 sec)
mysql> select * from t;
+------+
| a    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)
mysql> show profiles;
+----------+------------+-----------------------------------+
| Query_ID | Duration   | Query                             |
+----------+------------+-----------------------------------+
|        1 | 0.00051675 | show variables like '%profil%'    |
|        2 | 0.00052600 | show variables like '%profiling%' |
|        3 | 0.00010600 | SELECT DATABASE()                 |
|        4 | 0.00025225 | show databases                    |
|        5 | 0.00012550 | show tables                       |
|        6 | 0.00021525 | select * from t                   |
+----------+------------+-----------------------------------+
6 rows in set, 1 warning (0.00 sec)
mysql> show profile for query 6;     --查看Query_ID为6的查询语句所消耗的资源

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

| Status               | Duration |
+----------------------+----------+
| starting             | 0.000058 |
| checking permissions | 0.000007 |
| Opening tables       | 0.000020 |
| init                 | 0.000015 |
| System lock          | 0.000010 |
| optimizing           | 0.000004 |
| statistics           | 0.000012 |
| preparing            | 0.000011 |
| executing            | 0.000002 |
| Sending data         | 0.000037 |
| end                  | 0.000004 |
| query end            | 0.000007 |
| closing tables       | 0.000008 |
| freeing items        | 0.000010 |
| cleaning up          | 0.000012 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)
mysql> show profile BLOCK IO,CPU,MEMORY for query 6;
+----------------------+----------+----------+------------+--------------+---------------+
| Status               | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting             | 0.000058 | 0.000000 |   0.000000 |            0 |             0 |
| checking permissions | 0.000007 | 0.000000 |   0.000000 |            0 |             0 |
| Opening tables       | 0.000020 | 0.000000 |   0.000000 |            0 |             0 |
| init                 | 0.000015 | 0.000000 |   0.000000 |            0 |             0 |
| System lock          | 0.000010 | 0.000000 |   0.000000 |            0 |             0 |
| optimizing           | 0.000004 | 0.000000 |   0.000000 |            0 |             0 |
| statistics           | 0.000012 | 0.000000 |   0.000000 |            0 |             0 |
| preparing            | 0.000011 | 0.000000 |   0.000000 |            0 |             0 |
| executing            | 0.000002 | 0.000000 |   0.000000 |            0 |             0 |
| Sending data         | 0.000037 | 0.000000 |   0.000000 |            0 |             0 |
| end                  | 0.000004 | 0.000000 |   0.000000 |            0 |             0 |
| query end            | 0.000007 | 0.000000 |   0.000000 |            0 |             0 |
| closing tables       | 0.000008 | 0.000000 |   0.000000 |            0 |             0 |
| freeing items        | 0.000010 | 0.000000 |   0.000000 |            0 |             0 |
| cleaning up          | 0.000012 | 0.000000 |   0.000000 |            0 |             0 |
+----------------------+----------+----------+------------+--------------+---------------+
15 rows in set, 1 warning (0.00 sec)
mysql> create table t2(a int);
Query OK, 0 rows affected (0.30 sec)
mysql> show profiles;
+----------+------------+-----------------------------------+
| Query_ID | Duration   | Query                             |
+----------+------------+-----------------------------------+
|        1 | 0.00051675 | show variables like '%profil%'    |
|        2 | 0.00052600 | show variables like '%profiling%' |
|        3 | 0.00010600 | SELECT DATABASE()                 |
|        4 | 0.00025225 | show databases                    |
|        5 | 0.00012550 | show tables                       |
|        6 | 0.00021525 | select * from t                   |
|        7 | 0.00023775 | help 'show profile'               |
|        8 | 0.07420075 | insert into t values(2)           |
|        9 | 0.00017425 | create table t1(a int)            |
|       10 | 0.29320100 | create table t2(a int)            |
+----------+------------+-----------------------------------+
10 rows in set, 1 warning (0.00 sec)
mysql> show profile BLOCK IO,CPU,MEMORY for query 10;   --查看Query_ID为10的查询语句所消耗的资源

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

| Status               | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting             | 0.000059 | 0.000000 |   0.000000 |            0 |             0 |
| checking permissions | 0.000007 | 0.000000 |   0.000000 |            0 |             0 |
| Opening tables       | 0.000059 | 0.000000 |   0.000000 |            0 |             0 |
| creating table       | 0.259481 | 0.002000 |   0.000000 |            0 |           280 |
| After create         | 0.000026 | 0.000000 |   0.000000 |            0 |             0 |
| query end            | 0.033376 | 0.000000 |   0.000000 |            0 |             8 |
| closing tables       | 0.000016 | 0.000000 |   0.000000 |            0 |             0 |
| freeing items        | 0.000160 | 0.000000 |   0.000000 |            0 |             0 |
| cleaning up          | 0.000018 | 0.000000 |   0.000000 |            0 |             0 |
+----------------------+----------+----------+------------+--------------+---------------+
9 rows in set, 1 warning (0.00 sec)
mysql> 

本文转自 z597011036 51CTO博客,原文链接:http://blog.51cto.com/tongcheng/1650613,如需转载请自行联系原作者
你可能感兴趣的文章
转:Eclipse自动补全功能轻松设置
查看>>
ES6新特性:Javascript中的Reflect对象
查看>>
hibernate逆向工程生成的实体映射需要修改
查看>>
mysql update操作
查看>>
Robots.txt - 禁止爬虫(转)
查看>>
MySQL数据库
查看>>
项目分析_xxoo-master
查看>>
SQLServer2012自增列值跳跃的问题
查看>>
ViewBag对象的更改
查看>>
Mysql 监视工具
查看>>
hdu1025 Constructing Roads In JGShining's Kingdom(二分+dp)
查看>>
Android PullToRefreshListView和ViewPager的结合使用
查看>>
禅修笔记——硅谷最受欢迎的情商课
查看>>
struts2入门(搭建环境、配置、示例)
查看>>
Caused by: org.apache.ibatis.reflection.ReflectionException我碰到的情况,原因不唯一
查看>>
linux top命令查看内存及多核CPU的使用讲述【转】
查看>>
Linux下golang开发环境搭建
查看>>
jQuery操作input
查看>>
layer弹出信息框API
查看>>
delete from inner join
查看>>