mysql5.7 慢日志查询

2019-11-26

开始慢日志查询:

1、修改配置文件:永久有效

    slow_query_log = ON   慢日志开启
    log_queries_not_using_indexes = ON  没有使用索引的
    long_query_time=0.5  超过5秒的语句才算慢sql  才会被记住
    slow_query_log_file=D:\slow.log   日志文件位置

2、使用sql语句:只有当次连接有效,服务重启后失效

     set global slow_query_log=on;  开启慢日志
     set long_query_time=5; 设置慢查询的时间


查看慢日志是否开启
show variables like '%query%';

查看慢查询的次数
show status like '%query%';
Slow_queries 慢查询的次数

mysqldumpslow slow-mysql.log //mysql提供的工具用来分析慢sql

性能查询:
    set profiling=on    开启性能 
    show profile          列出所有查询的语句及时间
    show profile for query 2   2是上面语句查询出来的id,能列出查询时每步操作设置的时间

    数据库缓存关闭,把设置设置大一点就是开启
    set global query_cache_size=0

{/if}