当前位置:网站首页>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会很麻烦.
边栏推荐
猜你喜欢

2022.07.18 _ a day

Fund investment advisory business

MySQL安装到最后一步 write configuration file 失败 怎么办?及后安装步骤

基于LSTM的诗词生成

会话技术之Coookie && Session详解

PHP中 比较 0、false、null,‘‘ “

进程和线程的区别&&run和start区别与联系

NK-RTU980烧写裸机程序

Leetcode952. Calculate maximum component size by common factor

'vite' is not an internal or external command, nor is it a runnable program or batch file.
随机推荐
van-uploader上传图片,使用base64回显无法预览的问题
页面懒加载
分布式缓存系统必须要解决的四大问题
Fund investment advisory business
Titanic 预测问题
【面试:并发篇38:多线程:线程池】ThreadPoolExecutor类的基本概念
使用PageHelper实现分页查询(详细)
‘vite‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
2022.07.24_Daily Question
CNN--各层的介绍
2022.07.20_Daily Question
The Ballad of Lushan Sends Lu's Servant to the Void Boat
The Spark run on Yarn Spark application
MySQL详解
MySQL table creation statement_Three commonly used MySQL table creation statements
波士顿房价数据集 Boston house prices dataset
实用生物信息学2:多组学数据整合和挖掘
Financial leasing business
进程和线程的区别&&run和start区别与联系
MySQL安装到最后一步 write configuration file 失败 怎么办?及后安装步骤