Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
960 views
in Technique[技术] by (71.8m points)

mysql - How to run a query to find a string in blob files?

Mediawiki has a table in the database 'text' which contains the page content. It is saved as a [BLOB] file. I would like to run a query to search through all the text on the site to see which pages contain a certain 'string'. How do I run a query to search [blob] files?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Mediawiki markup text is stored in the old_text field, which is a mediumblob type. You can query it like any other text-based field. MySQL will cast your string into binary for the query. Note that this is a case-sensitive search!

select old_id from text where old_text like "%string%";

If you need case-insensitivity then you need to apply an appropriate character set with a case-insensitive collation to the column:

SELECT old_id from text where CONVERT(old_text USING latin1) like '%STRing%';

Be aware that if your table isn't small these queries will take a long time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...