MYSQLPROCGREP(1)

NAME
mysqlprocgrep - Search Server Process Lists

SYNOPSIS

mysqlprocgrep [options]

DESCRIPTION

This utility scans the process lists for the servers specified using instances of the --server option and selects those that match the conditions specified using the --age and --match-xxx options. For a process to match, all conditions given must match. The utility then either prints the selected processes (the default) or executes certain actions on them.

If no --age or --match-xxx options are given, the utility selects all processes.

The --match-xxx options correspond to the columns in the INFORMATION_SCHEMA.PROCESSLIST table. For example, --match-command specifies a matching condition for PROCESSLIST.COMMAND column values. There is no --match-time option. To specify a condition based on process time, use --age.

Processes that can be seen and killed are subject to whether the account used to connect to the server has the PROCESS and SUPER privileges. Without PROCESS, the account cannot see processes belonging to other accounts Without SUPER, the account cannot kill processes belonging to other accounts.

When the --kill-query or --kill-connection option is used, the utility displays those rows from the SHOW PROCESSLIST that match the query and are killed. This behavior exists as of MySQL Utilities 1.6.0.

To specify how to display output, use one of the following values with the --format option:

    • grid (default)

    Display output in grid or table format like that of the mysql client command-line tool.

    • csv

    Display output in comma-separated values format.

    • tab

    Display output in tab-separated format.

    • vertical

    Display output in single-column format like that of the \G command for the mysql client command-line tool.
Options.PP mysqlprocgrep accepts the following command-line options:

    • --help

    Display a help message and exit.

    • --license

    Display license information and exit.

    • --age=time

    Select only processes that have been in the current state more than a given time. The time value can be specified in two formats: either using the hh:mm:ss format, with hours and minutes optional, or as a sequence of numbers with a suffix giving the period size.

    The permitted suffixes are s (second), m (minute), h (hour), d (day), and w (week). For example, 4h15m represents 4 hours and 15 minutes.

    For both formats, the specification can optionally be preceded by + or -, where + means older than the given time, and - means younger than the given time.

    • --character-set=charset

    Sets the client character set. The default is retrieved from the server variable character_set_client.

    • --format=format, -fformat

    Specify the output display format. Permitted format values are grid (default), csv, tab, and vertical.

    • --kill-connection

    Kill the connection for all matching processes (like the KILL CONNECTION statement).

    • --kill-query

    Kill the query for all matching processes (like the KILL QUERY statement).

    • --match-command=pattern

    Match all processes where the Command field matches the pattern.

    • --match-db=pattern

    Match all processes where the Db field matches the pattern.

    • --match-host=pattern

    Match all processes where the Host field matches the pattern.

    • --match-id=pattern

    Match all processes where the ID field matches the pattern.

    • --match-info=pattern

    Match all processes where the Info field matches the pattern.

    • --match-state=pattern

    Match all processes where the State field matches the pattern.

    • --match-user=pattern

    Match all processes where the User field matches the pattern.

    • --print

    Print information about the matching processes. This is the default if no --kill-connection or --kill-query option is given. If a kill option is given, --print prints information about the processes before killing them.

    • --regexp, --basic-regexp, -G

    Perform pattern matches using the REGEXP operator. The default is to use LIKE for matching. This affects the --match-xxx options.

    • --server=source

    Connection information for a server. Use this option multiple times to search multiple servers.

    To connect to a server, it is necessary to specify connection parameters such as the user name, host name, password, and either a port or socket. MySQL Utilities provides a number of ways to supply this information. All of the methods require specifying your choice via a command-line option such as --server, --master, --slave, etc. The methods include the following in order of most secure to least secure.

        • Use login-paths from your .mylogin.cnf file (encrypted, not visible). Example : login-path[:port][:socket]

        • Use a configuration file (unencrypted, not visible) Note: available in release-1.5.0. Example : configuration-file-path[:section]

        • Specify the data on the command-line (unencrypted, visible). Example : user[:passwd]@host[:port][:socket]

    • --sql, --print-sql, -Q

    Instead of displaying the selected processes, emit the SELECT statement that retrieves information about them. If the --kill-connection or --kill-query option is given, the utility generates a stored procedure named kill_processes() for killing the queries rather than a SELECT statement.

    • --sql-body

    Like --sql, but produces the output as the body of a stored procedure without the CREATE PROCEDURE part of the definition. This could be used, for example, to generate an event for the server Event Manager.

    When used with a kill option, code for killing the matching queries is generated. Note that it is not possible to execute the emitted code unless it is put in a stored routine, event, or trigger. For example, the following code could be generated to kill all idle connections for user www-data:

        shell> mysqlprocgrep --kill-connection --sql-body \
                  --match-user=www-data --match-state=sleep
        DECLARE kill_done INT;
        DECLARE kill_cursor CURSOR FOR
          SELECT
                Id, User, Host, Db, Command, Time, State, Info
              FROM
                INFORMATION_SCHEMA.PROCESSLIST
              WHERE
                  user LIKE 'www-data'
                AND
                  State LIKE 'sleep'
        OPEN kill_cursor;
        BEGIN
           DECLARE id BIGINT;
           DECLARE EXIT HANDLER FOR NOT FOUND SET kill_done = 1;
           kill_loop: LOOP
              FETCH kill_cursor INTO id;
              KILL CONNECTION id;
           END LOOP kill_loop;
        END;
        CLOSE kill_cursor;

    • --ssl-ca

    The path to a file that contains a list of trusted SSL CAs.

    • --ssl-cert

    The name of the SSL certificate file to use for establishing a secure connection.

    • --ssl-key

    The name of the SSL key file to use for establishing a secure connection.

    • --ssl

    Specifies if the server connection requires use of SSL. If an encrypted connection cannot be established, the connection attempt fails. Default setting is 0 (SSL not required).

    • --verbose, -v

    Specify how much information to display. Use this option multiple times to increase the amount of information. For example, -v = verbose, -vv = more verbose, -vvv = debug.

    • --version

    Display version information and exit.
NOTES.PP For the --format option, the permitted values are not case sensitive. In addition, values may be specified as any unambiguous prefix of a valid value. For example, --format=g specifies the grid format. An error occurs if a prefix matches more than one valid value.

The path to the MySQL client tools should be included in the PATH environment variable in order to use the authentication mechanism with login-paths. This permits the utility to use the my_print_defaults tools which is required to read the login-path values from the login configuration file (.mylogin.cnf). EXAMPLES.PP For each example, assume that the root user on localhost has sufficient privileges to kill queries and connections.

Kill all connections created by user john:

    shell> mysqlprocgrep --server=root@localhost \
              --match-user=john --kill-connection --format=CSV
    # The following KILL commands were executed:
    Id,User,Host,db,Command,Time,State,Info
    4,john,localhost:50706,mysql,Sleep,5,,

Kill all connections that have been idle for more than 1 hour:

    shell> mysqlprocgrep --server=root@localhost \
              --match-command=sleep --age=1h --kill-connection

PERMISSIONS REQUIRED.PP The user must have the SELECT privilege on the mysql database.

COPYRIGHT

Copyright © 2006, 2017, Oracle and/or its affiliates. All rights reserved.

This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see http://www.gnu.org/licenses/.

SEE ALSO
For more information, please refer to the MySQL Utilities and Fabric documentation, which is available online at http://dev.mysql.com/doc/index-utils-fabric.html

AUTHOR
Oracle Corporation (http://dev.mysql.com/).