简体   繁体   中英

Search MySQL database for string in schema

I have a fairly large MySQL database with several dozen tables. 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?

You can use the INFORMATION_SCHEMA table to find out the columns of each table.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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