当前位置:网站首页>MySQL 慢查询
MySQL 慢查询
2022-04-23 04:57:00 【促酒】
一. 慢查询介绍
MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录在MySQL中响应时间超过指定阀值的SQL语句,运行时间超过long_query_time值的SQL,会被记录到慢查询日志中。
默认情况下,MySQL数据库并不启动慢查询日志,需要手动开启。如果不是调优需要的话,一般不建议开启,因为开启慢查询日志会或多或少带来一定的性能影响。
在SQL Server中我们利用SQL Profile来记录SQL执行情况,在Oracle中我们可以使用AWR、ASH报告来分析历史SQL执行情况,类似的调优方式映射到MySQL中,即对应为慢查询日志。
二. 参数介绍
slow_query_log:是否开启慢查询日志,1表示开启,0表示关闭。
slow_query_log_file:MySQL慢查询日志存储路径。
long_query_time :慢查询阈值(s),当查询时间多于设定的阈值时,记录日志。
log_queries_not_using_indexes:未使用索引的查询也被记录到慢查询日志中。
log_throttle_queries_not_using_indexes:表示每分钟允许记录到slow_log的且未使用索引的sql语句次数(0为无限制,如果为固定值,可能会记录不到sql)。
log_output:日志存储方式。’FILE’表示存入文件,‘TABLE’表示存入系统表。因为FILE模式开销比较低,所以默认为FILE。
log_slow_admin_statements = 1: 记录ALTER TABLE等语句引发的慢查询
log_slow_slave_statements = 1:记录从服务器产生的慢查询
min_examined_row_limit = 100 :SQL扫描行数大于等于100行才会被记录
是否开启慢查询日志
show variables like '%slow_query_log%';
慢查询阈值(s),当查询时间多于设定的阈值时,记录日志
show variables like '%long_query_time%';
三. 开启慢查询日志
-- 慢查询阈值(s),当查询时间多于设定的阈值时,记录日志。
set global long_query_time = 2;
-- 未使用索引的查询也被记录到慢查询日志中
set global log_queries_not_using_indexes = 1;
-- 表示每分钟允许记录到slow_log的且未使用索引的sql语句次数(0为无限制,如果为固定值,可能会记录不到sql)。
set global log_throttle_queries_not_using_indexes = 0;
-- QL扫描行数大于等于100行才会被记录
set global min_examined_row_limit = 100;
-- 开启
set global slow_query_log = 1;
版权声明
本文为[促酒]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44275894/article/details/124352009
边栏推荐
- ApplicationContext injection bean
- Alibaba tip: it is better to create threads manually
- The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
- Teach you how to build the ruoyi system by Tencent cloud
- QPushbutton 槽函数被多次触发
- Detailed explanation of the differences between TCP and UDP
- Mac 进入mysql终端命令
- Spark case - wordcount
- JS engine loop mechanism: synchronous, asynchronous, event loop
- PHP+MySQL 制作留言板
猜你喜欢
MySQL - index
Detailed explanation of the differences between TCP and UDP
CLion+OpenCV identify ID number - detect ID number
What are the redis data types
Learning Android II from scratch - activity
独立站运营 | FaceBook营销神器——聊天机器人ManyChat
Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]
Unity rawimage background seamlessly connected mobile
View, modify and delete [database] table
Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!
随机推荐
Detailed explanation of hregionserver
MySQL memo (for your own query)
[WinUI3]编写一个仿Explorer文件管理器
Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases
JS determines whether the numeric string contains characters
[2021] Spatio-Temporal Graph Contrastive Learning
Sword finger offer: symmetric binary tree (recursive iteration leetcode 101)
Windows remote connection to redis
La caméra Unity tourne avec la souris
用LCR表完美测试无线充电系统中的线圈
ApplicationContext injection bean
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
深度学习笔记 —— 语义分割和数据集
【数据库】MySQL单表查询
CLion+OpenCV identify ID number - detect ID number
Machine learning - linear regression
Unity攝像頭跟隨鼠標旋轉
Agile practice | agile indicators to improve group predictability
List remove an element
Pixel 5 5g unlocking tutorial (including unlocking BL, installing edxposed and root)