zoukankan      html  css  js  c++  java
  • mysql优化——定位慢查询

    1.定位慢查询

    1、show status 命令

    命令使用方式:show [session|global] status like 'slow_queries'

    如果你不写  [session|global] 默认是session 会话,指取出当前窗口的执行,如果你想看所有(从mysql 启动到现在,则应该 global)

    执行show status 显示的数据库变量大概有291个。变量对应说明:

    http://www.ttlsa.com/mysql/mysql_show_status_descriptsions/

    http://blog.chinaunix.net/uid-20204919-id-1972099.html

    http://lxneng.iteye.com/blog/451985

    show status 常用的命令:

    show status like ‘uptime’ ; 

    show  stauts like ‘com_select’ 

     show stauts like ‘com_insert’ 

    ...类推 update  delete

    show status like ‘connections’; 

    //显示慢查询次数

    show status like ‘slow_queries’;

    2、mysql默认的慢查询

    默认情况下,mysql认为10秒才是一个慢查询.

    show variables like ‘long_query_time’ ; //可以显示当前慢查询时间

    set long_query_time=1 ;//可以修改慢查询时间

    3、定位慢查询

    show variables like '%slow%';   #查看MySQL慢查询是否开启

    set global slow_query_log=ON;   #开启MySQL慢查询功能

    show variables like "long_query_time";  #查看MySQL慢查询时间设置,默认10秒

    set global long_query_time=5;  #修改为记录5秒内的查询

    select sleep(6);  #测试MySQL慢查询

    show variables like "%slow%";  #查看MySQL慢查询日志路径

    show global status like '%slow%';  #查看MySQL慢查询状态

    或者

    vi  /etc/my.cnf  #编辑,在[mysqld]段添加以下代码

    slow-query-log = on  #开启MySQL慢查询功能

    slow_query_log_file =  /var/run/mysqld/mysqld-slow.log #设置MySQL慢查询日志路径

    long_query_time = 5  #修改为记录5秒内的查询,默认不设置此参数为记录10秒内的查询

    log-queries-not-using-indexes = on  #记录未使用索引的查询

    :wq! #保存退出

    service mysqld restart #重启MySQL服务

    4、安装使用MySQL慢查询分析工具mysqlsla

    采菊东篱下,悠闲现南山~
  • 相关阅读:
    python3给socket模块设置代理
    yield、greenlet与协程gevent
    线程池
    并发通信、生产者与消费者模型
    多进程和多线程
    非阻塞套接字与IO多路复用
    14.python模块之subprocess
    判断页面是否滑到底部
    @vue/cli 3.x 版本配置productionGzip提高性能
    vue跳转到指定位置
  • 原文地址:https://www.cnblogs.com/ChaosJu/p/4749441.html
Copyright © 2011-2022 走看看