MySql 高阶二(SQL 性能分析)

SQL 性能分析:

查看当前数据库的 增删改查的使用情况

sql 复制代码
show global status like 'Com_______';

慢查询日志:

sql 复制代码
-- 查看状态
show variables like 'slow_query_log'

目前是开启状态。如何开启,编辑my.cnf 文件 添加下面的语句,编辑完成后重启Mysql服务

powershell 复制代码
vim /etc/my.cnf  #编辑my.cnf文件

#新增下面3句
slow_query_log=1  # 开启慢sql
slow-query-log-file=/www/mysql-slow.log  #存放日志的地方
long_query_time=3    # 表示超过3秒就记录下来。

#重启Mysql服务:
systemctl restart mysqld

之后如果定时查看 /www/mysql-slow.log 日志,就可以看是否有查过3秒的慢sql

下是一个例子。

查看sql 耗时情况

sql 复制代码
select @@have_profiling;  -- 查看数据库支付支持 
select @@profiling;   -- 查看是否开启
set profiling = 1;    -- 开启profiling
sql 复制代码
select * from a_img where id = 10
select * from a_img where img_url like '%24SN%'
show profiles;

通过 profiles就可以查看到最近 sql的执行时间

sql 复制代码
show profile cpu for query 126;   #查询执行过程耗时:
相关推荐
zuoerjinshu4 小时前
sql实战解析-sum()over(partition by xx order by xx)
数据库·sql
NocoBase5 小时前
【2.0 教程】第 1 章:认识 NocoBase ,5 分钟跑起来
数据库·人工智能·开源·github·无代码
Hoshino.417 小时前
基于Linux中的数据库操作——下载与安装(1)
linux·运维·数据库
Oueii8 小时前
Django全栈开发入门:构建一个博客系统
jvm·数据库·python
未来龙皇小蓝9 小时前
【MySQL-索引调优】11:Group by相关概念
数据库·mysql·性能优化
2401_831824969 小时前
使用Fabric自动化你的部署流程
jvm·数据库·python
njidf9 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
twc8299 小时前
大模型生成 QA Pairs 提升 RAG 应用测试效率的实践
服务器·数据库·人工智能·windows·rag·大模型测试
@我漫长的孤独流浪9 小时前
Python编程核心知识点速览
开发语言·数据库·python
2401_851272999 小时前
实战:用Python分析某电商销售数据
jvm·数据库·python