システムのコードが入ったリポジトリでgrepを使って検索するというのはよくあることです。全体の中にどこに該当するテキストがあるのか分からない場合、まずは全体を探してみるでしょう。 今回紹介するmysqlgrepはMySQLで使えるGrepです。テーブルを指定する必要もなく、一気に検索できます。

mysqlgrepの使い方

mysqlgrepのヘルプです。

$ ./mysqlgrep 

  Usage: mysqlgrep -u username -h hostname -d database -t table pattern
    -u username : mysql username to connect with (default: root).
    -h hostname : hostname of mysql server to connect to (default: localhost).
    -d database : name of mysql database
    -t table    : name of the table to search within. If not provided, all tables will be searched.
    -l          : only list which tables contain a match, don't display actual data
    pattern     : the pattern to search for.

使い方としてはデータベースを指定して検索する文字を入力するだけです。

$ ./mysqlgrep -u app -d wordpress "メインサイト"
wp_options (option_id=174):
      * option_value: a:4:{s:5:"child";a:1:{s:0:"";a:1:{s:3:"rss";a:1:{i:0;a:6:{s:4:"data";s:3:"
	";s:7:"attribs";a:0:{}s:8:"xml_base";s:0:"";s:17:"xml_base_explicit";b:0;s:8:"xml_lang";s:0:"";s:5:"child";a:2:{s:0:"";a:7:{s:5:"title";a:1:{i:0;a:5:{s:4:"data";s:25:"日本語 » Recent 
  :

後は検索にマッチしたテーブル名と該当部分がリストアップされます。データがどこにあるか分かれば、システムの分析なども進めやすくなるでしょう。

mysqlgrepはPerl製のオープンソース・ソフトウェア(MIT License)です。

rhinst/mysqlgrep: Utility to search for a string in any field in any or all tables in a mysql database.