MySQL全文查詢的方法並不難,下面就為您詳細介紹MySQL全文查詢的實現方法,希望對您學習MySQL全文查詢方面能夠有所幫助。
到3.23.23時,MySQL開始支持全文索引和搜索。全文索引在MySQL中是一個FULLTEXT類型索引。FULLTEXT索引用於 MyISAM 表,可以在CREATE TABLE時或之後使用ALTER TABLE或 CREATE INDEX 在 CHAR、VARCHAR 或 TEXT 列上創建。對於大的數據庫,將數據裝載到一個沒有FULLTEXT索引的表中,然後再使用 ALTER TABLE (或 CREATE INDEX) 創建索引,這將是非常快的。將數據裝載到一個已經有FULLTEXT索引的表中,將是非常慢的。
全文搜索通過 MATCH() 函數完成。
- mysql> CREATE TABLE articles (
- -> id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
- -> title VARCHAR(200),
- -> body TEXT,
- ->FULLTEXT(title,body)
- -> );
- Query OK, 0 rows affected (0.00 sec)
- mysql> INSERT INTO articles VALUES
- -> (NULL,\'MySQLTutorial\', \'DBMS stands for DataBase ...\'),
- -> (NULL,\'How To UseMySQLEfficiently\', \'After you went through a ...\'),
- -> (NULL,\'OptimisingMySQL\',\'In this tutorial we will show ...\'),
- -> (NULL,\'1001MySQLTricks\',\'1. Never runMySQLd as root. 2. ...\'),
- -> (NULL,\'MySQLvs. YourSQL\', \'In the following database comparison ...\'),
- -> (NULL,\'MySQLSecurity\', \'When configured properly,MySQL...\');
- Query OK, 6 rows affected (0.00 sec)
- Records: 6 Duplicates: 0 Warnings: 0
- mysql> SELECT * FROM articles
- -> WHERE MATCH (title,body) AGAINST (\'database\');
- +----+-------------------+------------------------------------------+
- | id | title | body |
- +----+-------------------+------------------------------------------+
- | 5 |MySQLvs. YourSQL | In the following database comparison ... |
- | 1 |MySQLTutorial | DBMS stands for DataBase ... |
- +----+-------------------+------------------------------------------+
- 2 rows in set
MySQL查詢結果條數編號示例
MySQL查詢中間記錄的方法
使用函數實現MySQL查詢行號
MySQL查詢超時問題的解決
MySQL日期函數和時間函數