当前位置:网站首页>Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting
Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting
2022-08-03 01:37:00 【One Light Architecture】
携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第5天,点击查看活动详情
1. 慢查询日志的作用
Slow query log is disabled by default,It is recommended to manually enable,Help us locate online problems.
执行时间超过阈值的SQLWill be written to the slow query log,This can help us to record the execution time is too longSQL语句,Positioning line slowSQL问题,方便我们进行SQL性能调优.
2. 慢查询日志的配置
2.1 查看是否开启了慢查询日志
show variables like 'slow_query_log';
复制代码默认是OFF,不开启,可以手动开启.
2.2 开启慢查询日志
一种方法是可以使用MySQL命令开启:
set global slow_query_log=1;
复制代码另一种方法是修改MySQL配置文件,重新MySQL服务后,开启.
修改配置文件my.cnf,Add the following line of a command
slow_query_log = ON
2.3 设置慢查询日志的阈值
The default threshold for slow query logs is10,单位是秒.
对于线上服务来说,10seconds are too long,我们可以手动修改.
一种是通过MySQL命令修改,比如修改为1秒:
set long_query_time=1;
复制代码另一种方法是修改MySQL配置文件,重新MySQL服务后,开启.
修改配置文件my.cnf,Add the following line of a command
long_query_time = 1
2.4 Modify slow query log location
使用MySQLCommand to view slow query log location:
show variables like '%slow_query_log_file%';
复制代码Want to modify the slow query log location,可以修改MySQL配置文件,重新MySQL服务后,开启.
修改配置文件my.cnf,Add the following line of a command
slow_query_log_file = /usr/local/mysql/data/localhost_slow.log
2.5 Log more slow queriesSQL
By default, management statements are not recorded in the slow query log,管理语句包括ALTER TABLE、 ANALYZE TABLE、 CHECK TABLE、 CREATE INDEX、 DROP INDEX、 OPTIMIZE TABLE和 REPAIR TABLE等.
Management statements are also very important,If you want to be recorded,可以通过MySQL命令修改:
set global log_slow_admin_statements=ON;
复制代码默认情况下,Statements that do not use an index,Is not recorded.
enough shit!Falling into a pit without noticing,Statements that do not use an index are not logged,Why do you want to query the log slowly??
Want to record without the use of the index of statements,可以通过命令修改:
set global log_queries_not_using_indexes=ON;
复制代码3. 慢查询日志的使用
Manually make a slowSQL,测试一下效果,user表中有100Multimeter data:
select * from user;
复制代码Then look at the contents of the slow query log file:
cat /usr/local/mysql/data/localhost_slow.log
复制代码SQLStatements and execution times are logged.
4. 分析慢查询日志
Sometimes there are many slow query logs,The manual is not very easy for you to see,好在MySQLProvides tools for analyzing slow query logsmysqldumpslow.
常用参数有
-s: 表示按何种方式排序:
c: 访问次数
l: 锁定时间
r: 返回记录
t: 查询时间
al: 平均锁定时间
ar: 平均返回记录数
at: 平均查询时间
-t: 返回前面多少条的数据;
复制代码4.1 The query returns the most results10条SQL:
mysqldumpslow -s r -t 10 /usr/local/mysql/data/localhost_slow.log
4.2 The longest query10条SQL:
mysqldumpslow -s t -t 10 /usr/local/mysql/data/localhost_slow.log
边栏推荐
猜你喜欢

No-code development platform form styling steps introductory course

【C语言】带头双向循环链表(list)详解(定义、增、删、查、改)

1 - vector R language self-study
![[论文总结] 深度学习在农业领域应用论文笔记10](/img/e8/0ba741980495cd81ca30bf269d1111.jpg)
[论文总结] 深度学习在农业领域应用论文笔记10

主流定时任务解决方案全横评

redis的学习笔记

Test | ali internship 90 days in life: from the perspective of interns, talk about personal growth

vscode 自定义快捷键——设置eslint

mysql根据多字段分组——group by带两个或多个参数

markdown语法
随机推荐
买母婴产品先来京东“券民空间站”抢券!大牌好物低至5折
微信小程序实现lot开发09 接入微信登录
markdown语法
MYSQL查看表结构
用了 TCP 协议,数据一定不会丢吗?
MySQL 与InnoDB 下的锁做朋友 (四)行锁/记录锁
华为设备配置BFD与接口联动(触发与BFD联动的接口物理状态变为Down)
qt静态编译出现Project ERROR: Library ‘odbc‘ is not defined
Pytest配置项-pytest.ini
语音合成模型小抄(1)
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
Cholesterol-PEG-Acid,胆固醇-聚乙二醇-羧基保持在干燥、低温环境下
ORA-55610: Invalid DDL statement on history-tracked table
IDEA 重复代码的黄色波浪线取消设置
精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队
Day117.尚医通:生成挂号订单模块
CIO修炼手册:成功晋升CIO的七个秘诀
学习基因富集工具DAVID(3)
典型相关分析CCA计算过程
resubmit 渐进式防重复提交框架简介