如何通过 mysql 数据库进行 grep?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/451922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how do I grep through a mysql database?
提问by Aaron Fi
Looking for a nifty helper function/method for grepping through all defined tables, columns, stored procedures, etc, for a MySql database.
寻找一个漂亮的帮助函数/方法来为 MySql 数据库搜索所有定义的表、列、存储过程等。
I had something similar for SQL Server.
我对 SQL Server 有类似的东西。
采纳答案by Sarel Botha
In the INFORMATION_SCHEMA database:
在 INFORMATION_SCHEMA 数据库中:
select * from columns WHERE TABLE_NAME LIKE '%tablename%' AND COLUMN_NAME LIKE '%columnname%'
More info here: http://dev.mysql.com/doc/refman/5.0/en/information-schema.html
更多信息:http: //dev.mysql.com/doc/refman/5.0/en/information-schema.html
Ok, it doesn't completely answer your question but you should be able to put it together how you want from here.
好的,它并不能完全回答您的问题,但是您应该能够从这里按照您想要的方式将其组合在一起。
回答by ykaganovich
mysqldump --compact --skip-extended-insert -u root -proot mydb | grep "interesting string"
mysqldump --compact --skip-extended-insert -u root -proot mydb | grep "interesting string"
回答by NexusRex
There is a stored procedure here (http://forge.mysql.com/tools/tool.php?id=232) for MySQL which will create a table for storing output, then loop through information_schema database's COLUMNS table to obtain all database's table and column names. Next execute a count() query on database.table for each column with appropriate search string in where condition. If count() > 0, that perticular column has the search term, so it will insert that triplet (database name, table name, column name) into a table. Last Select * from table to view respective database table and column names having the search term.
这里有一个用于 MySQL的存储过程(http://forge.mysql.com/tools/tool.php?id=232),它会创建一个表来存储输出,然后遍历 information_schema 数据库的 COLUMNS 表以获取所有数据库的表和列名。接下来对每个列在 database.table 上执行 count() 查询,并在 where 条件中使用适当的搜索字符串。如果 count() > 0,则该特定列具有搜索词,因此它将将该三元组(数据库名称、表名称、列名称)插入到表中。最后从表中选择 * 以查看具有搜索词的相应数据库表和列名称。
回答by Craig
Common Resource Grep (crgrep) searches for table/column name and data matches and supports MySQL.
Common Resource Grep (crgrep) 搜索表/列名称和数据匹配并支持 MySQL。
http://sourceforge.net/projects/crgrep/
http://sourceforge.net/projects/crgrep/
Also searches other hard to search resources like content buried in archives. I developed crgrep as an opensource tool.
还搜索其他难以搜索的资源,例如隐藏在档案中的内容。我开发了 crgrep 作为开源工具。
回答by Dominik Zawadzki
or simple, MySQL Workbench -> Database -> Search Table Data...
或者简单的,MySQL Workbench -> Database -> Search Table Data...