性能测试Mysql之profiling参数
一、查看profiling状态
1 | mysql> select @ @profiling ; |
0:表示为关闭
1:表示开启
二、开启 profiling
1 | mysql> SET profiling= 1 ; |
三、show profiles 命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | mysql> show profiles; +----------+------------+--------------------------------------------+ | Query_ID | Duration | Query | +----------+------------+--------------------------------------------+ | 1 | 0.00007100 | select profiling | | 2 | 0.00010800 | select @ @profiling | | 3 | 0.00004875 | show profiling | | 4 | 0.00031000 | show tables | | 5 | 0.00015800 | select count( 1 ) from emp | | 6 | 0.00017575 | select count( 1 ) from dept | | 7 | 0.00021650 | select * from emp | | 8 | 0.00017050 | select * from emp where location_id= '1800' | +----------+------------+--------------------------------------------+ 8 rows in set, 1 warning ( 0.00 sec) |
查看所有语句消耗的具体时间(Duration)和使用的查询(Query )
四、单query获取详细的profile的信息
语法:
show profile for query query_id
查看具体的query_ID所经历的过程以及消耗的资源详细分析报告
1. 查询 Query_ID=5信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | mysql> show profile for query 5 ; +----------------------+----------+ | Status | Duration | +----------------------+----------+ | starting | 0.000041 | | checking permissions | 0.000004 | | Opening tables | 0.000011 | | init | 0.000009 | | System lock | 0.000005 | | optimizing | 0.000003 | | statistics | 0.000007 | | preparing | 0.000006 | | executing | 0.000001 | | Sending data | 0.000026 | | end | 0.000002 | | query end | 0.000004 | | closing tables | 0.000004 | | freeing items | 0.000006 | | logging slow query | 0.000025 | | cleaning up | 0.000007 | +----------------------+----------+ 16 rows in set, 1 warning ( 0.00 sec) |
2. 查询 Query_ID=5的cup、io信息
cpu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | mysql> show profile cpu for query 5 ; +----------------------+----------+----------+------------+ | Status | Duration | CPU_user | CPU_system | +----------------------+----------+----------+------------+ | starting | 0.000041 | 0.000023 | 0.000014 | | checking permissions | 0.000004 | 0.000003 | 0.000002 | | Opening tables | 0.000011 | 0.000006 | 0.000004 | | init | 0.000009 | 0.000006 | 0.000003 | | System lock | 0.000005 | 0.000003 | 0.000002 | | optimizing | 0.000003 | 0.000001 | 0.000001 | | statistics | 0.000007 | 0.000004 | 0.000002 | | preparing | 0.000006 | 0.000004 | 0.000002 | | executing | 0.000001 | 0.000001 | 0.000001 | | Sending data | 0.000026 | 0.000016 | 0.000009 | | end | 0.000002 | 0.000001 | 0.000001 | | query end | 0.000004 | 0.000002 | 0.000001 | | closing tables | 0.000004 | 0.000003 | 0.000002 | | freeing items | 0.000006 | 0.000003 | 0.000002 | | logging slow query | 0.000025 | 0.000016 | 0.000009 | | cleaning up | 0.000007 | 0.000004 | 0.000003 | +----------------------+----------+----------+------------+ |
CPU_user:当前用户占用的 CPU;
CPU_system:当前系统占用的CPU。
io:
1 2 3 4 5 6 7 8 9 | mysql> show profile block io for query 5 ; ±--------------±---------±-------------±--------------+ | Status | Duration | Block_ops_in | Block_ops_out | ±--------------±---------±-------------±--------------+ | starting | 0.000036 | 0 | 0 | | freeing items | 0.000009 | 0 | 0 | | cleaning up | 0.000004 | 0 | 0 | ±--------------±---------±-------------±--------------+ 3 rows in set, 1 warning ( 0.00 sec) |
查看所有参数,使用如下命令:
show profile all for query 5
标签:
性能测试
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下