当前位置:网站首页>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
边栏推荐
- 信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮
- Innovation training (IV) preliminary preparation - server
- [winui3] write an imitation Explorer file manager
- POI export message list (including pictures)
- Spark small case - RDD, spark SQL
- Unity camera rotation with sliding effect (rotation)
- The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
- Alibaba tip: it is better to create threads manually
- C. Tree Infection(模拟+贪心)
- Gets all dates between two times
猜你喜欢

《2021多多阅读报告》发布,95后、00后图书消费潜力攀升

2022/4/22

Innovation training (IX) integration

redis数据类型有哪些
![[winui3] write an imitation Explorer file manager](/img/3e/62794f1939da7f36f7a4e9dbf0aa7a.png)
[winui3] write an imitation Explorer file manager

用LCR表完美测试无线充电系统中的线圈

Perfect test of coil in wireless charging system with LCR meter

Making message board with PHP + MySQL

View analysis of scenic spots in ArcGIS

DIY is an excel version of subnet calculator
随机推荐
Differences between redis and MySQL
泰克示波器DPO3054自校准SPC失败维修
List remove an element
How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
Analysis of POM files
Teach you how to build the ruoyi system by Tencent cloud
COM in wine (2) -- basic code analysis
Implementation of switching windows and capturing data in selenium mode
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
Painless upgrade of pixel series
退出vim的方法
ApplicationContext injection bean
MySQL memo (for your own query)
selenium模式下切换窗口,抓取数据的实现
[WinUI3]編寫一個仿Explorer文件管理器
使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
Custom switch control
Harmonious dormitory (linear DP / interval DP)
What is the meaning of load balancing