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;   #查询执行过程耗时:
相关推荐
Gofarlic_oms113 小时前
构建可视化监控体系实现ANSYS许可证可观测管理
大数据·运维·网络·数据库·人工智能
weixin_5860614613 小时前
为什么Bootstrap的下拉菜单在Firefox下显示异常
jvm·数据库·python
qq_1898070313 小时前
如何导出特定分区_EXPDP TABLES=表名-分区名进行单区数据备份
jvm·数据库·python
Shorasul14 小时前
c++ 跨平台线程封装 c++如何封装pthread和std--thread
jvm·数据库·python
tingting011914 小时前
安全之-mysql 命令
数据库·mysql
2401_8326355814 小时前
CSS如何利用Sass简化CSS书写_通过嵌套与简写优化编码效率
jvm·数据库·python
2402_8548083714 小时前
如何处理MongoDB跨分片事务报错_4.2+分布式事务的限制与两阶段提交延迟
jvm·数据库·python
SPC的存折14 小时前
自用LNMP-Redis-NFS-Discuz5.0部署指南-脚本版
linux·运维·服务器·数据库·redis·mysql·缓存
vegetablec14 小时前
如何进行SQL数学计算_运用ROUND与CEIL处理数值精度
jvm·数据库·python
coderlin_14 小时前
Langgraph项目 一(mysql,es,qdrant,embedding模块)
mysql·elasticsearch·embedding