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;

发布了168 篇原创文章 · 获赞 16 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/ajax_yan/article/details/105087747