---
title: "全文索引"
author: "xiajava2011"
date: "2011-05-06T17:33:19Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2011-05-06T17:33:19Z"
id: 1033780
url: "https://xiajava2011.iteye.com/blog/1033780"
---

MySQL支持[**全文**]() [**索引**]() 和搜索功能。MySQL中的全文索引类型FULLTEXT的索引。  FULLTEXT 索引仅可用于 MyISAM 表；他们可以从CHAR、 VARCHAR或TEXT列中作为CREATE TABLE语句的一部分被创建，或是随后使用 ALTER TABLE 或 CREATE INDEX被添加。对于较大的数据集，将你的资料输入一个没有FULLTEXT索引的表中，然后创建索引， 其速度比把资料输入现有FULLTEXT索引的速度更为快。

全文搜索同MATCH()[**函数**]() 一起执行

mysql &gt; CREATE TABLE articles (  
    -&gt;   id INT UNSIGNED AUTO\_INCREMENT NOT NULL PRIMARY KEY,  
    -&gt;   title VARCHAR(200),  
    -&gt;   body TEXT,  
    -&gt;   FULLTEXT (title,body))ENGINE = MyISAM;  
Query OK, 0 rows affected (0.00 sec)

mysql&gt; INSERT INTO articles (title,body) VALUES  
    -&gt; ('MySQL Tutorial','DBMS stands for DataBase ...'),  
    -&gt; ('How To Use MySQL Well','After you went through a ...'),  
    -&gt; ('Optimizing MySQL','In this tutorial we will show ...'),  
    -&gt; ('1001 MySQL Tricks','1. Never run mysqld as [**root**]() . 2. ...'),  
    -&gt; ('MySQL vs. YourSQL','In the following database comparison ...'),  
    -&gt; ('MySQL Security','Whenconf igured properl y, MySQL ...');  
Query OK, 6 rows affected (0.00 sec)  
Records: 6  Duplicates: 0  Warnings: 0

mysql&gt; SELECT * FROM articles  
    -&gt; WHERE MATCH (title,body) AGAINST ('database');  
+----+-------------------+------------------------------------------+  
| id | title             | body                                     |  
+----+-------------------+------------------------------------------+  
|  5 | MySQL vs. YourSQL | In the following database comparison ... |  
|  1 | MySQL Tutorial    | DBMS stands for DataBase ...             |  
+----+-------------------+------------------------------------------+  
2 rows in set (0.00 sec)