当前位置:网站首页>MySql database optimization query tool
MySql database optimization query tool
2022-07-31 08:00:00 【@@Shen Nong write code】
一、MySql数据库监控工具 Profile
- Profile工具
用来统计SQL语句的执行时间. - 条件
- Profile工具
- MySql数据库
- 步骤
打开Profile
# 打开Profile set profiling = 1;执行sql语句
# 执行sql语句sql语句分析
# sql分析 show profiles;如图:

sqlThe time for each procedure of the statement execution
# sqlThe time for each procedure of the statement execution show profile for query 5;如图:

分析过程
# 分析过程 show profile all for query 5;关闭监控
set profiling = 0;如图:

缺陷
- 只能在mysql客户端对sql进行性能分析.
- 解决方案
- 使用索引 sqlThe performance of the statement is improved entirely by the index
- 使用缓存
- mysql本地缓存
- 使用webapi [IMemoryCache]
- 使用分布式缓存 [redis]
二、SqlInquire about technical tools Explain [推荐使用]
- 目的
主要用来分析sqlHow statements are optimized. - 步骤
开启 Explain
explain [sql语句]; # 例如 explain select * from Table;如图:

- 表结构说明
字段名称 备注 id sqlExecute sequence number select_type 查询类型 table 表名 partitions 分区 type 是否使用索引 possible_keys Possible index names to use key The final decision on the index name to use key_len 查询索引使用的字节数,通常是越少越好 尽量在INTAdd an index on the type ref 查询的列或常量 rows 需要扫描的行数 filtered 过滤 extra 额外的信息 - Table field properties
- select_type [查询类型]
- 单表查询:SIMPLE;
- 联合查询:PRIMARY[The first of a union querysql];UNION[联合sql];
- 子查询:PRIMARY[首先执行的sql语句];SUBQUERY[子查询];
- 关联查询:PRIMARY[首先执行的sql语句];
- DEPENDENT SUBQUERY[依赖子查询,The main table must be queried to get the results,side table dependency,不走索引,性能很慢];
- DEPENDENT UNION[跟UNION相同,But rely on the outer query results];DERIVED[临时表;用于FROM 中的子查询]
- type [是否使用索引]
- ALL:全表扫描;
- const:常量[性能最高 1对1 查询,Set to primary key or set tounqiue索引];
- ref:A field uses an index;
- eq_ref:Indexes are used in joint queries;
- range:[索引范围查找];
- index:[组合索引]
- select_type [查询类型]
- Table field properties
- The purpose of using a query plan
- Know how many rows the target data is from
- Query whether the target data uses the index
- 执行了多少sql语句
- 表结构说明
三、Sql慢查询日志分析
- The concept of slow queries
A slow query refers to a record that takes a long time to executesql语句. - 步骤
Check whether the slow query is enabled in the system
show variables like '%slow_query_log%';如图:

开启慢查询
#开启 [0:关闭 1:开启] set global slow_query_log = 1;如图:

Can be modifiedmysqlThe configuration file sets the enable of slow query、File storage path and monitoring time,并重启mysql服务
执行慢SQL语句
- 缺陷
- Concurrency is high in production environments,生成很多的sql日志,排查慢sql会很麻烦.
边栏推荐
- 金融租赁业务
- "C language" frog jumping steps recursion problem
- CNN--各层的介绍
- 2022.07.15_Daily Question
- 2022.07.12_Daily Question
- MySQL installation to the last step in the write the configuration file failed?And after the installation steps
- 【面试题】从输入URL到游览器渲染完成,经历了什么
- LED flashing on CY7C68013A
- 最大似然估计和最小二乘法 含代码
- linux redis6.2.6配置文件
猜你喜欢

MySQL详解

Zabbix6.2 Surprise Release!Especially optimize the performance of medium and large environment deployment!

CNN--Introduction to each layer

使用PageHelper实现分页查询(详细)

最大似然估计和最小二乘法 含代码

解决安装 Bun 之后出现 zsh compinit: insecure directories, run compaudit for list. Ignore insecure directorie

NK - RTU980 burning bare-metal program

"The C language games" mine clearance

DAY18: XSS vulnerability

Tasks and task switching
随机推荐
2022.07.18 _ a day
HighTec 的安装与配置
"The C language games" mine clearance
Open Source | Commodity Recognition Recommender System
Machine Learning - Notes and Implementation of Linear Regression, Logistic Regression Problems
[PSQL] 复杂查询
循环结构--for循环
超级详细的mysql数据库安装指南
ros little turtle drawing
Visual Studio新功能出炉:低优先级构建
NK - RTU980 burning bare-metal program
《opencv学习笔记》-- 仿射变换
2022.07.20_Daily Question
Zabbix6.2 Surprise Release!Especially optimize the performance of medium and large environment deployment!
我开发了一个利用 Bun 执行 .ts / .js 文件的 VS Code 插件
Reimbursement Process | By Tianfang
MySQL detailed explanation
mysql插入新字段方法
@Transactional注解的失效场景
基于交替迭代法的交直流混合系统潮流计算matlab程序iEEE9节点系统算例