MySQL FULLTEXT Search
Also Known As
MySQL FULLTEXT
MATCH AGAINST MySQL
full text search PHP
TL;DR
A built-in MySQL search engine supporting natural language and boolean full-text queries on TEXT and VARCHAR columns.
Explanation
FULLTEXT indexes enable MATCH(col) AGAINST('query') syntax. Natural language mode ranks results by relevance. Boolean mode supports operators: +required, -excluded, *wildcard, "phrase". Minimum word length (ft_min_word_len, default 4) affects which words are indexed — short words like 'PHP' are excluded unless the config is changed. InnoDB FULLTEXT is available since MySQL 5.6. For complex search needs, Elasticsearch or MeiliSearch provide better relevance tuning, tokenisation, and multilingual support.
Common Misconception
✗ MySQL FULLTEXT search is equivalent to Elasticsearch. MySQL FULLTEXT lacks advanced features like stemming, faceted search, and distributed indexing — use Elasticsearch for large-scale or multilingual search.
Why It Matters
LIKE '%keyword%' requires a full table scan and cannot rank results by relevance. FULLTEXT search is index-backed and returns relevance scores, making it suitable for search boxes on medium-sized datasets.
Common Mistakes
- Searching for words shorter than ft_min_word_len (default 4) — they're excluded from the index silently.
- Using FULLTEXT on MyISAM tables — works, but no transactions; prefer InnoDB.
- Expecting FULLTEXT to handle typos or fuzzy matching — it doesn't without external preprocessing.
Avoid When
- Do not use MySQL FULLTEXT for large-scale or multilingual search — use Elasticsearch or MeiliSearch.
- Do not expect FULLTEXT to match words shorter than ft_min_word_len (default 4) — 'PHP' will not match.
When To Use
- Use FULLTEXT for search boxes on medium-sized datasets (under a few million rows).
- Use boolean mode when users need exact control — required terms (+), excluded terms (-), wildcards (*).
Code Examples
✗ Vulnerable
-- LIKE full table scan — no relevance ranking
SELECT * FROM articles WHERE body LIKE '%php security%'; -- slow, no ranking
✓ Fixed
-- Create FULLTEXT index
CREATE FULLTEXT INDEX idx_search ON articles (title, body);
-- Natural language search (relevance ranked)
SELECT id, title,
MATCH(title, body) AGAINST('php security' IN NATURAL LANGUAGE MODE) AS score
FROM articles
WHERE MATCH(title, body) AGAINST('php security' IN NATURAL LANGUAGE MODE)
ORDER BY score DESC
LIMIT 20;
-- Boolean mode (exact control)
SELECT * FROM articles
WHERE MATCH(title, body) AGAINST('+php +security -deprecated' IN BOOLEAN MODE);
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
31 Mar 2026
Views
15
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Perplexity 6
Google 3
Unknown AI 2
Meta AI 1
Ahrefs 1
Also referenced
How they use it
crawler 12
crawler_json 1
Related categories
⚡
DEV INTEL
Tools & Severity
⚙ Fix effort: Medium
⚡ Quick Fix
Create a FULLTEXT index on searchable columns and use MATCH...AGAINST instead of LIKE '%keyword%'
📦 Applies To
web
🔗 Prerequisites
🔍 Detection Hints
LIKE '%keyword%' on TEXT/VARCHAR columns
Auto-detectable:
✓ Yes
semgrep
⚠ Related Problems
🤖 AI Agent
Confidence: Medium
False Positives: Low
✗ Manual fix
Fix: Medium
Context: File
Tests: Update