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;   #查询执行过程耗时:
相关推荐
哆啦A梦15882 小时前
Springboot整合MyBatis实现数据库操作
数据库·spring boot·mybatis
Zzzzmo_2 小时前
【MySQL】JDBC(含settings.xml文件配置/配置国内镜像以及pom.xml文件修改)
数据库·mysql
FirstFrost --sy4 小时前
MySQL内置函数
数据库·mysql
2401_879693874 小时前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
reembarkation4 小时前
光标在a-select,鼠标已经移出,下拉框跟随页面滚动
java·数据库·sql
eggwyw4 小时前
MySQL-练习-数据汇总-CASE WHEN
数据库·mysql
星轨zb4 小时前
通过实际demo掌握SpringSecurity+MP中的基本框架搭建
数据库·spring boot·spring security·mp
treacle田4 小时前
达梦数据库-配置本地守护进程dmwatcher服务-记录总结
数据库·达梦数据库·达梦数据库local数据守护
wyt5314295 小时前
Redis的安装教程(Windows+Linux)【超详细】
linux·数据库·redis
CeshirenTester5 小时前
从数据库到结构化用例:一套可落地的测试智能体架构
数据库·架构