Tuesday, November 15, 2011

Showing running queries in MySQL

The syntax is simply:
show processlist;

The "info" column shows the query being executedm or NULL if there's nothing currently happening. When running "show processlist" it will only show the first 100 characters of the query. To show the full query run "show full processlist" instead.
Running the above command from the MySQL command line interface with a ; delimiter can make it difficult to read the output, especially if the queries are long and span multiple lines. Using the \G delimiter instead will show the data in what is often a more readable format, although it consumes more rows in your terminal. This is espcially useful when running "show full processlist" because some of the queries displayed may be quite long.
mysql> show processlist\G
 
*************************** 1. row ***************************
     Id: 454543
   User: root
   Host: localhost
     db: NULL
Command: Query
   Time: 0
  State: NULL
   Info: show processlist
*************************** 2. row ***************************
     Id: 454547
   User: test
   Host: localhost
     db: test
Command: Query
   Time: 3
  State: sending the query
   Info: select * from calls
2 rows in set (0.00 sec)



If you want to KILL the Thread ID

KILL [CONNECTION | QUERY] thread_id

KILL QUERY terminates the statement that the connection is currently executing, but leaves the connection itself intact.

Example:

Mysql> KILL 454547;

0 comments:

Post a Comment