简体   繁体   English

在MySQL数据库中搜索架构中的字符串

[英]Search MySQL database for string in schema

I have a fairly large MySQL database with several dozen tables. 我有一个相当大的MySQL数据库,其中包含几十个表。 I'm removing some legacy data and I'm looking for a quick way to search for a string throughout the database schema (not in the data itself). 我正在删除一些旧数据,并且正在寻找一种快速方法来搜索整个数据库模式中的字符串(而不是数据本身)。 I'm looking for columns that have a particular string. 我正在寻找具有特定字符串的列。 Is there a built in way of doing this or should I just write a sql script to dump the schema and search it with php? 是否有内置的方法来执行此操作,还是只写一个sql脚本以转储模式并使用php搜索?

You can use the INFORMATION_SCHEMA table to find out the columns of each table. 您可以使用INFORMATION_SCHEMA表找出每个表的列。

SELECT 
    `COLUMN_NAME`
FROM 
    `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE 
    `TABLE_SCHEMA` = 'database_name' 
AND 
    `TABLE_NAME` LIKE '%search%'

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM