先生,您需要的是 MySQL 的 FULLTEXT 索引。
这是一个详细的示例,可以满足您的需求。
http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html
编辑这是一个纯 SQL 解决方案。
为了方便SO,我在这里复制了相关的SQL:
CREATE TABLE articles (
d INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
ENGINE=MyISAM;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
SELECT id, body, MATCH (title,body) AGAINST
('Security implications of running MySQL as root') AS score
FROM articles WHERE MATCH (title,body) AGAINST
('Security implications of running MySQL as root');