windows 下mysql5.7 设置慢查询

目的:为什么要开启慢查询?就是为了让mysql帮助记录下查询超过long_query_time的sql语句,进而对sql进行优化

windows 下mysql5.7 慢查询配置

查看慢配置查询的 
show variables like ‘%query%’;

这里写图片描述

show variables like ‘long_query_time’ ; //可以显示当前慢查询时间 
set long_query_time=1 ; //慢查询的时间默认为10秒 可以修改慢查询时间也可

mysql5.7 可以直接在配置文件my.ini 中写配置 
/start*
log_slow_admin_statements = ON 
log_slow_slave_statements = ON 
slow_query_log = 1 //开启慢查询 (很多博客说=on    off ,我本机mysql实际是1 ,2 )
slow_query_log_file = E:\MySQL-5.7.13-winx64\data\pc-PC-slow.log //设置路径 
long_query_time =1 //设置慢查询时间 超过一秒的记录 
/end*/

以在my.ini种配置

/********************************************************/

查看sql语句执行时间

Show variables like ‘profiling’; 查看sql语句 性能分析 
看profile是否开启 5.7的 
mysql> show variables like ‘%profiling%’; 
+————————+——-+ 
| Variable_name | Value | 
+————————+——-+ 
| have_profiling | YES | 
| profiling | ON | 
| profiling_history_size | 15 | 
+————————+——-+ 
set profiling=on; 开启profile 
查看执行过的sql 的执行时间 
show profiles;

mysql> show profiles; 
+———-+————+——————————————————————————-+ 
| Query_ID | Duration | Query | 
+———-+————+——————————————————————————-+ 
| 1 | 0.00081975 | explain select * from t_log_login where id=’46702e55f23911e49d5cac162d8aadd4’ | 
| 2 | 0.00436950 | select * from t_log_login where id=’46702e55f23911e49d5cac162d8aadd4’ | 
+———-+————+——————————————————————————-+ 
查询所花费的时间 query_id=1 的语句执行时间

select sum(duration) from information_schema.profiling where query_id=1; # Query ID = 1

查看 # Query ID = 1的执行时间 
mysql> show profile for query 1;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

励志重写JDK

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值