当前位置:网站首页>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会很麻烦.
边栏推荐
- Embedded system driver primary [2] - _ parameters and dependencies under the kernel module
- XSS详解
- Financial leasing business
- 2022.07.20_Daily Question
- 2022.07.15_每日一题
- Zabbix6.2惊喜发布!特别优化中大型环境部署的性能!
- 嵌入式系统驱动初级【2】——内核模块下_参数和依赖
- MySQL installation to the last step in the write the configuration file failed?And after the installation steps
- Zabbix6.2 Surprise Release!Especially optimize the performance of medium and large environment deployment!
- The first part of the R language
猜你喜欢
2704:寻找平面上的极大点
Linked list implementation and task scheduling
Pygame Surface对象
《opencv学习笔记》-- 仿射变换
2022.07.12_每日一题
MySQL详解
2022.07.29_每日一题
2022.07.24_每日一题
[Interview: Concurrency 38: Multithreading: Thread Pool] Basic concepts of the ThreadPoolExecutor class
Zabbix6.2 Surprise Release!Especially optimize the performance of medium and large environment deployment!
随机推荐
Vscode:Project-tree插件
Leetcode952. Calculate maximum component size by common factor
双倍数据速率同步动态随机存储器(Double Data Rate Synchronous Dynamic Random Access Memory, DDR SDRAM)- 逻辑描述部分
【愚公系列】2022年07月 Go教学课程 022-Go容器之字典
DAY18: Xss Range Clearance Manual
DAY18:XSS 漏洞
Environment_Variable_and_SetUID
2022.07.26_Daily Question
2022.07.22_每日一题
Thread 类的基本用法——一网打尽
Linked list implementation and task scheduling
任务及任务切换
7/28-7/29 期望+思维+后缀数组+ST表
Locust 1.0版本引入的变化
完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
2022.07.14_每日一题
第9章 异常try...except...else...finally
把 VS Code 当游戏机
金融租赁业务
ros小乌龟画图