This module searches processes on a server and optionally kills either the query or the connection for all matches.
Processes are matched by searching the fields of the
Internally, the module operates by constructing a
SELECT statement for finding
matching processes, and then sending it to the server. Instead of
performing the search, the module can return the SQL code that
performs the query. This can be useful if you want to execute the
query later or feed it to some other program that processes SQL
The following constants correspond to fields in the
They indicate which columns to examine when searching for
processes matching the search conditions.
The following constants indicate actions to perform on processes that match the search conditions.
Kill the process query
Kill the process connection
Print the processes
class mysql.utilities.command.proc.ProcessGrep(matches, actions=, use_regexp=False)
This class searches the
for processes on MySQL servers and optionally kills them. It can
be used to perform a search (and optionally kill), or to generate
the SQL statement for doing the same.
For example, to kill all queries with user 'mats', use the following code:
>>> from mysql.utilities.command.proc import * >>> grep = ProcessGrep(matches=[(USER, "mats")], actions=[KILL_QUERY]) >>> grep.execute("firstname.lastname@example.org", "email@example.com")
matches (List of (var, pat) pairs)
Sequence of field comparison conditions. In each condition, var is one of the constants listed earlier that specify
PROCESSLISTtable fields and pat is a pattern. For a process to match, all field conditions must match.
Return the SQL code for executing the search (and optionally, the kill).
If only_body is
the body of the function is shown. This is useful if the SQL code
is to be used with other utilities that generate the routine
declaration. If only_body is
False, a complete procedure is generated if
there is any kill action supplied, and just a SELECT statement if
it is a plain search.
Show only the body of the procedure. If this is
False, a complete procedure is returned.
SQL code for executing the operation specified by the options.
execute(connections, ...[, output=sys.stdout, connector=mysql.connector])
Execute the search on each of the connections supplied. If
output is not
value is treated as a file object and the result of the execution
is printed on that stream. Note that the output and connector
arguments must be supplied as keyword
arguments. All other arguments are treated as connection
Sequence of connection specifiers to send the search to
File object to use for writing the result
Connector to use for connecting to the servers