Explore: how to query MySQL for currently running SQL statements
- 2020-05-19 06:05:34
- OfStack
Through the status command, view the 1 item Slow queries, if it is long
>
0 indicates that a query took too long to execute
At this point, the show processlist command is used to view the currently running SQL, find the slow running SQL statements, find the slow executing statements, and then use the explain command to see the execution plan of these statements.
mysql > show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| 53 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+----+------+-----------+------+---------+------+-------+------------------+
The following is a quote:
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
--------------
At this point, the show processlist command is used to view the currently running SQL, find the slow running SQL statements, find the slow executing statements, and then use the explain command to see the execution plan of these statements.
mysql > show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| 53 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+----+------+-----------+------+---------+------+-------+------------------+