Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Finding partial strings - Full Text?

I just found a bunch of rogue data in my MYSQL db...

The only way to get to it is via one of the columns - FILE_PATH which contains a slash stripped version of a file path. There are a few rogue files in this set that I need find - they all have the file name "Thumbs.db" but they have a variety of paths

example:

F:DatasetGroupedByFormatsx-fmt-398Thumbs.db

I have a full text index on the field, however the following query doesn't give any returns:

SELECT * FROM main_small WHERE MATCH `FILE_PATH` AGAINST  ('Thumbs.db')

Response:

MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0382 sec )

I am unsure whether this is because I have the syntax wrong, or whether the text string needs to be isolated by whitespace/punctuation.

like image 842
Jay Avatar asked Mar 05 '12 20:03

Jay


People also ask

How do I select a part of a string in MySQL?

SUBSTRING() function in MySQL function in MySQL is used to derive substring from any given string . It extracts a string with a specified length, starting from a given location in an input string. The purpose of substring is to return a specific portion of the string.

How do I find a word in a string MySQL?

MySQL LOCATE() Function The LOCATE() function returns the position of the first occurrence of a substring in a string. If the substring is not found within the original string, this function returns 0. This function performs a case-insensitive search. Note: This function is equal to the POSITION() function.

How do you check if a string contains a substring in MySQL?

MySQL query string contains using INSTRINSTR(str, substr) function returns the index of the first occurrence of the substring passed in as parameters. Here str is the string passed in as the first argument, and substr is the substring passed in as the second argument.

Is there a split function in MySQL?

There is no string split function in MySQL. so you have to create your own function.


3 Answers

Surely it's

select * from main_small where FILE_PATH like '%Thumbs.db'

However, if not then does MySql Full text Search help?

like image 140
Andrew Leach Avatar answered Oct 08 '22 21:10

Andrew Leach


The problem is that your query thinks 'Thumbs.db' is a whole word. You'll need to find some way to do wildcard searching in order to select those rows. How about:

SELECT * FROM main_small WHERE `FILE_PATH` LIKE '%Thumbs.db'
like image 22
curtisdf Avatar answered Oct 08 '22 19:10

curtisdf


Just use LIKE:

SELECT * FROM main_small WHERE `FILE_PATH` LIKE '%Thumbs.db'
like image 2
kitti Avatar answered Oct 08 '22 19:10

kitti