Link to home
Start Free TrialLog in
Avatar of submissiontechnology
submissiontechnology

asked on

Searching MySQL

Is there a query I can run to search all tables in a database for a particular string?
Something like this: select * from * where * like '%mysearchstring%'
Thanks.
Avatar of Raynard7
Raynard7

No - unfortunatley there is not
If you are using mysql v 5.0 + you potentially could create a function to do this for you - using the information schema to find all tables, then all columns and then search each for your particular value - but this would be very slow - difficult and hard to show the results.
Avatar of submissiontechnology

ASKER

What about searching just one table? Is that not possible either? It is MySQL 5 I have.
For all your fields - if they are string fields you could do

Select
sorry pressed enter too quickly
SOLUTION
Avatar of Raynard7
Raynard7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If it's something used every so often, do a text search on your backups (take your backups using mysqldump)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think Sheeri's point was if this is something used just for an occasional diagnostic by an admin, then taking a mysqldump of the database and searchingi that would be less trouble than a manual query through every column in every table.  I'd have to agree.

Certainly if this is functionality end users need, then the solution should be kept within the DBMS.
Hey,

I would take a look at http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html for a great list of examples of different database/table structures you can use on a "tagging" based system - although this kind of structure can be adapted for other uses also. I wouldn't recommend "MySQLicious" solution (like "%text%").

garreh
"%text%" is not "MySQLicious" -- all the database vendors have LIKE and allow wildcards -- just to be clear for the people reading this.

http://www.mysql.com/news-and-events/on-demand-webinars/web2.0-schema-design-2006-08-29.php has a free presentation on "Web 2.0 Tags and Folksonomy: Schema Design for Scalability and Performance" that you might want to check out.
Also, http://firestuff.org/wordpress/2006/07/20/sqlsearch-100/ might be useful -- InnoDB fulltext search that supports multi-column indexes.
Sheeri, "MySQLicious" is just a name for a database structure for mirroring del.icio.us bookmarks, which un-surprisingly the project is also called "MySQLicious" - hence the name "MySQLicious". I did not mention that MySQLicious is some kind of strange addon for MySQL. Nor did I imply that the LIKE operator is not available, or used in other database engines. So I don't see what exactly you are 'clearing' up.

garreh
ah, sorry.  I hadn't realized it was an actual tool.