mysqlmetagrep

mysqlmetagrep用来模糊查找对象

$ ./mysqlmetagrep --help
Usage: mysqlmetagrep --server=user:pass@host:port:socket [options] pattern
 
mysqlmetagrep - search metadata
 
Options:
  --version             show program's version number and exit
  --help                display a help message and exit
  --server=SERVER       connection information for the server in the form:
                        <user>[:<password>]@<host>[:<port>][:<socket>] or
                        <login-path>[:<port>][:<socket>].
  -b, --body            search the body of routines, triggers, and events as
                        well
  --search-objects=OBJECT_TYPES, --object-types=OBJECT_TYPES
                        the object type to search in: a comma-separated list
                        of one or more of: 'database', 'trigger', 'user',
                        'routine', 'column', 'table', 'partition', 'event',
                        'view'
  -G, --basic-regexp, --regexp
                        use 'REGEXP' operator to match pattern. Default is to
                        use 'LIKE'.
  -p, --print-sql, --sql
                        print the statement instead of sending it to the
                        server
  -e PATTERN, --pattern=PATTERN
                        pattern to use when matching. Required if the pattern
                        looks like a connection specification.
  --database=DATABASE_PATTERN
                        only look at objects in databases matching this
                        pattern
  -f FORMAT, --format=FORMAT
                        display the output in either grid (default), tab, csv,
                        or vertical format
root@luoxuan 11:01:16>show TABLES;
+-------------------+
| Tables_in_luoxuan |
+-------------------+
| test_index        |
| test_index2       |
| test_index3       |
+-------------------+

eg1:查找以test_inde开头,后面跟一个字符的对象

$ ./mysqlmetagrep --pattern="test_index_" --server=root@localhost
+------------------------+--------------+--------------+-----------+-------------+--------------+
| Connection             | Object Type  | Object Name  | Database  | Field Type  | Matches      |
+------------------------+--------------+--------------+-----------+-------------+--------------+
| root:*@localhost:3306  | TABLE        | test_index2  | luoxuan   | TABLE       | test_index2  |
| root:*@localhost:3306  | TABLE        | test_index3  | luoxuan   | TABLE       | test_index3  |
+------------------------+--------------+--------------+-----------+-------------+--------------+

eg2:查询对象中包含test_index字符(包括procedure、trigger等对象内的内容)
创建一个存储过程对test_index进行操作

$ ./mysqlmetagrep -b --pattern="%test_index%" --server=root@localhost      
+------------------------+--------------+--------------+-----------+-------------+--------------+
| Connection             | Object Type  | Object Name  | Database  | Field Type  | Matches      |
+------------------------+--------------+--------------+-----------+-------------+--------------+
| root:*@localhost:3306  | TABLE        | test_index   | luoxuan   | TABLE       | test_index   |
| root:*@localhost:3306  | TABLE        | test_index2  | luoxuan   | TABLE       | test_index2  |
| root:*@localhost:3306  | TABLE        | test_index3  | luoxuan   | TABLE       | test_index3  |
+------------------------+--------------+--------------+-----------+-------------+--------------+
$ ./mysqlmetagrep -b --pattern="%test" --server=root@localhost 
+------------------------+--------------+--------------+-----------+-------------+----------+
| Connection             | Object Type  | Object Name  | Database  | Field Type  | Matches  |
+------------------------+--------------+--------------+-----------+-------------+----------+
| root:*@localhost:3306  | PROCEDURE    | sp_test      | luoxuan   | ROUTINE     | sp_test  |
+------------------------+--------------+--------------+-----------+-------------+----------+

注意:存储过程名字并未显示,莫非是版本问题or bug?

eg3:使用REGEXP模式来匹配

$ ./mysqlmetagrep -Gb --pattern="test" --server=root@localhost 
+------------------------+--------------+--------------+-----------+-------------+--------------+
| Connection             | Object Type  | Object Name  | Database  | Field Type  | Matches      |
+------------------------+--------------+--------------+-----------+-------------+--------------+
| root:*@localhost:3306  | PROCEDURE    | sp_test      | luoxuan   | ROUTINE     | sp_test      |
| root:*@localhost:3306  | TABLE        | test_index   | luoxuan   | TABLE       | test_index   |
| root:*@localhost:3306  | TABLE        | test_index2  | luoxuan   | TABLE       | test_index2  |
| root:*@localhost:3306  | TABLE        | test_index3  | luoxuan   | TABLE       | test_index3  |
+------------------------+--------------+--------------+-----------+-------------+--------------+

Post a Comment