Solved

Searching MySQL

Posted on 2006-11-07
15
657 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:submissiontechnology
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +2
15 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17888250
No - unfortunatley there is not
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17888255
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.
0
 

Author Comment

by:submissiontechnology
ID: 17888336
What about searching just one table? Is that not possible either? It is MySQL 5 I have.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 35

Expert Comment

by:Raynard7
ID: 17888348
For all your fields - if they are string fields you could do

Select
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17888349
sorry pressed enter too quickly
0
 
LVL 35

Assisted Solution

by:Raynard7
Raynard7 earned 250 total points
ID: 17888352
For one table you would still need to write a query - there is no shortcut,

if all the columns are text columns you could do

select
    *
from
    tableName t
where
    t.field1 like '%mysearchstring%'
    or t.field2 like '%mysearchstring%'
    or t.field3 like '%mysearchstring%'

and do this for all fields,

there are no shortcuts to do these searches - you have to define where you wish to search (thats a "feature" of SQL)
0
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 250 total points
ID: 17888496
You may find it useful to explore use of a "FULLTEXT" index.  This would allow you to write, for a particular table..
SELECT *
FROM the_table
WHERE (field_a, field_b, c, d, e, f, g, h) MATCH ('whatever');

That still only allows you to search a single table, however, and has some limitations.

Perhaps it's worth asking: what's the ultimate goal?  Why do you need to look for a string anywhere in any table?
0
 
LVL 4

Expert Comment

by:Sheeri
ID: 17895386
If it's something used every so often, do a text search on your backups (take your backups using mysqldump)
0
 
LVL 35

Assisted Solution

by:Raynard7
Raynard7 earned 250 total points
ID: 17895422
I would strongly advise against doing a search through backup text files.

1.   This involves double the storage that you currently use
2.    It limits your backup options (ie just copying the myisam files)
3.    It would be very slow - and limited to one user at a time
4.    Finding the string is fine - however you then need to interpret what it means, meaning you would have to build a distinct application to track back through the backup file to find what table and column it relates to.

The fulltext search will work quite well as would my suggestion
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17895438
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.
0
 
LVL 4

Expert Comment

by:garreH
ID: 17948955
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
0
 
LVL 4

Expert Comment

by:Sheeri
ID: 17949047
"%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.
0
 
LVL 4

Expert Comment

by:Sheeri
ID: 17949060
Also, http://firestuff.org/wordpress/2006/07/20/sqlsearch-100/ might be useful -- InnoDB fulltext search that supports multi-column indexes.
0
 
LVL 4

Expert Comment

by:garreH
ID: 17949798
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
0
 
LVL 4

Expert Comment

by:Sheeri
ID: 17949902
ah, sorry.  I hadn't realized it was an actual tool.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question