Documentation Home
MySQL Utilities 1.5 Manual
Related Documentation Download this Manual
PDF (US Ltr) - 1.2Mb
PDF (A4) - 1.2Mb
EPUB - 365.4Kb
HTML Download (TGZ) - 287.5Kb
HTML Download (Zip) - 298.6Kb

MySQL Utilities 1.5 Manual  /  Manual Pages  /  mysqlmetagrep — Search Database Object Definitions

5.12 mysqlmetagrep — Search Database Object Definitions

This utility searches for objects matching a given pattern on all the servers specified using instances of the --server option. It produces output that displays the matching objects. By default, the first non-option argument is taken to be the pattern unless the --pattern option is given. If the --pattern option is given, then all non-option arguments are treated as connection specifications.

Internally, the utility generates an SQL statement for searching the necessary tables in the INFORMATION_SCHEMA database on the designated servers, and then executes it before collecting the result and printing it as a table. Use the --sql option to have mysqlmetagrep display the statement, rather than execute it. This can be useful if you want to feed the output of the statement to another application, such as the mysql client command-line tool.

The MySQL server supports two forms of patterns when matching strings: SQL Simple Patterns (used with the LIKE operator) and POSIX Regular Expressions (used with the REGEXP operator).

By default, the utility uses the LIKE operator to match the name (and optionally, the body) of objects. To use the REGEXP operator instead, use the --regexp option.


Because the REGEXP operator does substring searching, it is necessary to anchor the expression to the beginning of the string if you want to match the beginning of the string.

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.

SQL Simple Patterns

The simple patterns defined by the SQL standard consist of a string of characters with two characters that have special meaning: % (percent) matches zero or more characters, and _ (underscore) matches exactly one character.

For example:

  • 'john%'

    Match any string that starts with 'john'.

  • '%doe%'

    Match any string containing the word 'doe'.

  • '%_'

    Match any string consisting of one or more characters.

POSIX Regular Expressions

POSIX regular expressions are more powerful than the simple patterns defined in the SQL standard. A regular expression is a string of characters, optionally containing characters with special meaning.

Documenting these regular expressions goes beyond the scope of this manual, but the full syntax is described in the MySQL manual and other locations, such as executing 'man regex' in your terminal.

  • .

    Match any character.

  • ^

    Match the beginning of a string.

  • $

    Match the end of a string.

  • [axy]

    Match a, x, or y.

  • [a-f]

    Match any character in the range a to f (that is, a, b, c, d, e, or f).

  • [^axy]

    Match any character except a, x, or y.

  • a*

    Match a sequence of zero or more a.

  • a+

    Match a sequence of one or more a.

  • a?

    Match zero or one a.

  • ab|cd

    Match ab or cd.

  • a{5}

    Match five instances of a.

  • a{2,5}

    Match from two to five instances of a.

  • (abc)+

    Match one or more repetitions of abc.


mysqlmetagrep accepts the following command-line options:

  • --help

    Display a help message and exit.

  • --license

    Display license information and exit.

  • --body, -b

    Search the body of stored programs (procedures, functions, triggers, and events). The default is to match only the name.

  • --character-set=<charset>

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

  • --database=<pattern>

    Look only in databases matching this pattern.

  • --format=<format>, -f<format>

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

  • --object-types=<types>, --search-objects=<types>

    Search only the object types named in types, which is a comma-separated list of one or more of the values database, trigger, user, routine, column, table, partition, event and view.

    The default is to search in objects of all types.

  • --pattern=<pattern>, -e=<pattern>

    The pattern to use when matching. This is required when the first non-option argument looks like a connection specification rather than a pattern.

    If the --pattern option is given, the first non-option argument is treated as a connection specifier, not as a pattern.

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

    Perform pattern matches using the REGEXP operator. The default is to use LIKE for matching. This affects the --database and --pattern 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 user name, host name, password, and either a port or socket. MySQL Utilities provides a number of ways to provide 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, -p

    Print rather than executing the SQL code that would be executed to find all matching objects. This can be useful to save the statement for later execution or to use it as input for other programs.

  • --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-cert

    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).

  • --version

    Display version information and exit.


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 will allow 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).


Find all objects with a name that matches the pattern 't_' (the letter t followed by any single character):

shell> mysqlmetagrep --pattern="t_" --server=john@localhost
| Connection             | Object Type  | Object Name  | Database  |
| john:*@localhost:3306  | TABLE        | t1           | test      |
| john:*@localhost:3306  | TABLE        | t2           | test      |
| john:*@localhost:3306  | TABLE        | tm           | test      |

To find all object that contain 't2' in the name or the body (for routines, triggers, and events):

shell> mysqlmetagrep -b --pattern="%t2%" --server=john@localhost:3306
| Connection             | Object Type  | Object Name  | Database  |
| john:*@localhost:3306  | TRIGGER      | tr_foo       | test      |
| john:*@localhost:3306  | TABLE        | t2           | test      |

In the preceding output, the trigger name does not match the pattern, but is displayed because its body does.

This is the same as the previous example, but using the REGEXP operator. Note that in the pattern it is not necessary to add wildcards before or after t2:

shell> mysqlmetagrep -Gb --pattern="t2" --server=john@localhost

| Connection             | Object Type  | Object Name  | Database  |
| root:*@localhost:3306  | TRIGGER      | tr_foo       | test      |
| root:*@localhost:3306  | TABLE        | t2           | test      |


The user must have the SELECT privilege on the mysql database.

Download this Manual
PDF (US Ltr) - 1.2Mb
PDF (A4) - 1.2Mb
EPUB - 365.4Kb
HTML Download (TGZ) - 287.5Kb
HTML Download (Zip) - 298.6Kb
User Comments
Sign Up Login You must be logged in to post a comment.