当前位置:网站首页>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.12_每日一题
- 2022.07.20_Daily Question
- 中断及pendSV
- Open Source | Commodity Recognition Recommender System
- 解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
- 【面试:并发篇38:多线程:线程池】ThreadPoolExecutor类的基本概念
- 7/28-7/29 Expectation + thinking + suffix array + ST table
- 电脑开机密码怎么设置?如何给你的电脑加上“安全锁”
- 2022.07.15_每日一题
- Yu Mr Series 】 【 2022 July 022 - Go Go teaching course of container in the dictionary
猜你喜欢
2704:寻找平面上的极大点
Environment_Variable_and_SetUID
Failure scenarios of @Transactional annotations
Embedded system driver primary [2] - _ parameters and dependencies under the kernel module
Regarding "computing power", this article is worth reading
shell/bash脚本命令教程
Read Elephant Swap in one article, why does it bring such a high premium to ePLATO?
Super detailed mysql database installation guide
Client navicat installation tutorial
基于交替迭代法的交直流混合系统潮流计算matlab程序iEEE9节点系统算例
随机推荐
2704:寻找平面上的极大点
分布式缓存系统必须要解决的四大问题
interrupt and pendSV
navicat 新建数据库
Matlab学习第一天(持续更新中)
2022.07.13 _ a day
2022.07.29_每日一题
[PSQL] SQL Basic Course Reading Notes (Chapter1-4)
[PSQL] SQL基础教程读书笔记(Chapter1-4)
2022.07.12_Daily Question
2022.07.26_Daily Question
SCI写作指南
任务及任务切换
【微服务】(十六)—— 分布式事务Seata
Leetcode952. 按公因数计算最大组件大小
Client navicat installation tutorial
Linked list implementation and task scheduling
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
@Transactional注解的失效场景
48页智慧城市规划蓝图 解决方案