0

When searching a string in an mysql database without knowing in what table or column I might find it, I usually resort to

 mysqldump --extended-insert=FALSE --complete-insert=TRUE dbname|grep SomeString

That dumps a lot of unneeded data, ignores indeces invented for that exact purpose, and makes it rather hard to localize the results. Is there a more convenient and more performant way? (Except installing 3rd party software.)

About duplicate questions: As a comment pointed out, I am not restricted to SQL queries, but will accept any solution - may it be a bash script, some CLI function I might have not seen, or grepping the DB file as suggested.

Zsolt Szilagyi
  • 4,741
  • 4
  • 28
  • 44

1 Answers1

0

I found a find command that lists the file which contains a specific string:

find [path of data folder of database]/*.ibd -type f -exec grep -i '[search string]' {} +

Outputs when found:

Binary file [path]/[table].ibd matches

Doesn't outputs anything when not found.

Means:

find     : linux find command
path     : the path pointing to the database folder under mysql/data 
           directory which contains the table's ibd files
-type f  : only search for files
-exec    : execute this while listing

    grep -i  : case insensitive text search
    string   : string to search for

For others, read this:

https://serverfault.com/a/343177

Same usage here:

http://www.valleyprogramming.com/blog/linux-find-grep-commands-exec-combine-search

Taha Paksu
  • 15,371
  • 2
  • 44
  • 78