mysql忧化查看工具之profile

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

  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,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
2月前
|
关系型数据库 MySQL
elasticsearch对比mysql以及使用工具同步mysql数据全量增量
elasticsearch对比mysql以及使用工具同步mysql数据全量增量
26 0
|
3月前
|
关系型数据库 MySQL 数据库
rds迁移数据迁移工具选择
rds迁移数据迁移工具选择
78 3
|
5月前
|
SQL 关系型数据库 MySQL
MySQL——MySQL的图形化界面工具安装与使用
MySQL——MySQL的图形化界面工具安装与使用
164 0
|
2月前
|
关系型数据库 MySQL 数据库
rds安装数据库客户端工具
安装阿里云RDS的数据库客户端涉及在本地安装对应类型(如MySQL、PostgreSQL)的客户端工具。对于MySQL,可选择MySQL Command-Line Client或图形化工具如Navicat,安装后输入RDS实例的连接参数进行连接。对于PostgreSQL,可以使用`psql`命令行工具或图形化客户端如PgAdmin。首先从阿里云控制台获取连接信息,然后按照官方文档安装客户端,最后配置客户端连接以确保遵循安全指引。
113 1
|
8天前
|
存储 安全 关系型数据库
MySQL中使用percona-xtrabackup工具 三种备份及恢复 (超详细教程)
MySQL中使用percona-xtrabackup工具 三种备份及恢复 (超详细教程)
|
13天前
|
SQL 关系型数据库 MySQL
【MySQL-3】图形化界面工具DataGrip安装&配置&使用
【MySQL-3】图形化界面工具DataGrip安装&配置&使用
|
5月前
|
SQL 关系型数据库 MySQL
postgresql|数据库|MySQL数据库向postgresql数据库迁移的工具pgloader的部署和初步使用
postgresql|数据库|MySQL数据库向postgresql数据库迁移的工具pgloader的部署和初步使用
127 0
|
1月前
|
关系型数据库 MySQL 数据库
MySQL之show profile相关总结
综上所述,`SHOW PROFILE`是MySQL提供的一个用于查询性能分析的工具,可以帮助开发人员定位查询性能问题,并进行优化。通过分析每个阶段的执行时间和资源消耗情况,可以更好地理解查询的执行过程,从而提升数据库性能。
17 0
|
4月前
|
存储 安全 关系型数据库
4个MySQL优化工具AWR,帮你准确定位数据库瓶颈!
4个MySQL优化工具AWR,帮你准确定位数据库瓶颈!
52 0
|
4月前
|
数据可视化 关系型数据库 MySQL
使用Navicat工具创建MySQL数据库连接
使用Navicat工具创建MySQL数据库连接