Home > Database > Mysql Tutorial > MySQL查询正在运行的SQL语句_MySQL

MySQL查询正在运行的SQL语句_MySQL

WBOY
Release: 2016-06-01 13:59:46
Original
929 people have browsed it

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

以下是引用片段:

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


这时再通过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 |

+----+------+-----------+------+---------+------+-------+------------------+

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template