zoukankan      html  css  js  c++  java
  • MySQL中如何查询当前正在运行的SQL语句

    通过status命令,查看Slow queries这一项,如果值长时间>0,说明有查询执行时间过长

    mysql> status; 
    -------------- 
    mysql Ver 11.18 Distrib 3.23.58, for redhat-linux-gnu (i386) 
    Connection id: 53 
    Current database: (null) 
    Current user: root@localhost 
    Current pager: stdout 
    Using outfile: '' 
    Server version: 5.0.37-log 
    Protocol version: 10 
    Connection: Localhost via UNIX socket 
    Client characterset: latin1 
    Server characterset: latin1 
    UNIX socket: /tmp/mysql.sock 
    Uptime: 4 days 16 hours 49 min 57 sec 
    Threads: 1 Questions: 706 Slow queries: 0 Opens: 177 Flush tables: 1 Open tables:
    52 Queries per second avg: 0.002 
    

      这时再通过show processlist命令来查看当前正在运行的SQL,从中找出运行慢的SQL语句,找到执行慢的语句后,再用explain命令查看这些语句的执行计划。

    mysql> show processlist;
    +----+------+-----------+------+---------+------+-------+------------------+
    | Id | User | Host | db | Command | Time | State | Info |
    +----+------+-----------+------+---------+------+-------+------------------+
    | 53 | root | localhost | NULL | Query | 0 | NULL | show processlist |
    +----+------+-----------+------+---------+------+-------+------------------+
  • 相关阅读:
    BZOJ 1492 [NOI2007]货币兑换Cash
    BZOJ 2285 [Sdoi2011]保密
    BZOJ 2962 序列操作
    BZOJ 3197 [Sdoi2013]assassin
    BZOJ 3131 [Sdoi2013]淘金
    BZOJ 3532 [Sdoi2014]Lis
    BZOJ 1923 [Sdoi2010]外星千足虫
    BZOJ 4855 [Jsoi2016]轻重路径
    BZOJ 4289 PA2012 Tax
    微信开发之 微信支付
  • 原文地址:https://www.cnblogs.com/liudandandear/p/15525646.html
Copyright © 2011-2022 走看看