MySQL Full-Text Search: FULLTEXT, MATCH AGAINST and Boolean Mode

MySQL 55 min min read Updated: Nov 27, 2026 Intermediate
MySQL Full-Text Search: FULLTEXT, MATCH AGAINST and Boolean Mode
Intermediate Topic 3 of 3

Why Not LIKE?

LIKE '%word%' cannot use a normal index and has no idea about words or relevance. A FULLTEXT index splits text into words, so MySQL can find rows by word quickly and rank them.

Create a FULLTEXT Index

sql CREATE TABLE posts ( id INT PRIMARY KEY, title VARCHAR(100), body TEXT, FULLTEXT KEY ft_posts (title, body) ) ENGINE=InnoDB; INSERT INTO posts VALUES (1, 'Learning MySQL', 'MySQL is a popular relational database. Learn tables and queries.'), (2, 'Indexes explained', 'An index makes database searches fast. Indexes cost write speed.'), (3, 'Cooking pasta', 'Boil water, add salt, cook the pasta for ten minutes.'), (4, 'MySQL replication', 'Replication copies data from one MySQL server to another.'); SELECT id, title FROM posts WHERE MATCH(title, body) AGAINST ('database') ORDER BY id;

Result:

idtitle
1Learning MySQL
2Indexes explained

Natural Language Mode and Relevance

The default mode ranks rows. MATCH returns a relevance score you can select and sort by:

sql CREATE TABLE posts (id INT PRIMARY KEY, title VARCHAR(100), body TEXT, FULLTEXT KEY ft_posts (title, body)) ENGINE=InnoDB; INSERT INTO posts VALUES (1, 'Learning MySQL', 'MySQL is a popular relational database. Learn tables and queries.'), (2, 'Indexes explained', 'An index makes database searches fast. Indexes cost write speed.'), (3, 'Cooking pasta', 'Boil water, add salt, cook the pasta for ten minutes.'), (4, 'MySQL replication', 'Replication copies data from one MySQL server to another.'); SELECT id, title FROM posts WHERE MATCH(title, body) AGAINST ('mysql database') ORDER BY MATCH(title, body) AGAINST ('mysql database') DESC, id;

Result:

idtitle
1Learning MySQL
4MySQL replication
2Indexes explained

Row 1 contains both words, so it ranks first. Rows 2 and 4 contain one word each. Row 3 has neither and is not returned. The exact score is a decimal number that depends on the index statistics, so rely on the ordering rather than on the score value (you can select it with MATCH(...) AGAINST(...) AS score).

Boolean Mode

OperatorMeaningExample
+Word must be present+mysql
-Word must be absent-replication
*Prefix wildcardrepl*
"..."Exact phrase"relational database"
> <Raise or lower the rank of a word>fast
sql CREATE TABLE posts (id INT PRIMARY KEY, title VARCHAR(100), body TEXT, FULLTEXT KEY ft_posts (title, body)) ENGINE=InnoDB; INSERT INTO posts VALUES (1, 'Learning MySQL', 'MySQL is a popular relational database. Learn tables and queries.'), (2, 'Indexes explained', 'An index makes database searches fast. Indexes cost write speed.'), (3, 'Cooking pasta', 'Boil water, add salt, cook the pasta for ten minutes.'), (4, 'MySQL replication', 'Replication copies data from one MySQL server to another.'); SELECT id, title FROM posts WHERE MATCH(title, body) AGAINST ('+mysql -replication' IN BOOLEAN MODE) ORDER BY id;

Result:

idtitle
1Learning MySQL
sql CREATE TABLE posts (id INT PRIMARY KEY, title VARCHAR(100), body TEXT, FULLTEXT KEY ft_posts (title, body)) ENGINE=InnoDB; INSERT INTO posts VALUES (1, 'Learning MySQL', 'MySQL is a popular relational database.'), (2, 'Indexes explained', 'An index makes database searches fast. Indexes cost write speed.'), (4, 'MySQL replication', 'Replication copies data from one MySQL server to another.'); SELECT id, title FROM posts WHERE MATCH(title, body) AGAINST ('repl* index*' IN BOOLEAN MODE) ORDER BY id;

Result:

idtitle
2Indexes explained
4MySQL replication
sql CREATE TABLE posts (id INT PRIMARY KEY, title VARCHAR(100), body TEXT, FULLTEXT KEY ft_posts (title, body)) ENGINE=InnoDB; INSERT INTO posts VALUES (1, 'Learning MySQL', 'MySQL is a popular relational database. Learn tables and queries.'), (2, 'Indexes explained', 'The database index is a relational structure.'); SELECT id, title FROM posts WHERE MATCH(title, body) AGAINST ('"relational database"' IN BOOLEAN MODE) ORDER BY id;

Result:

idtitle
1Learning MySQL

Stopwords and Short Words

Very common words ("the", "is", "and") are stopwords and are not indexed. InnoDB also ignores words shorter than innodb_ft_min_token_size (3 characters by default). So a search for a two-letter word finds nothing:

sql CREATE TABLE notes (id INT PRIMARY KEY, body VARCHAR(100), FULLTEXT KEY ft_notes (body)) ENGINE=InnoDB; INSERT INTO notes VALUES (1, 'Go is a fast language'), (2, 'Rust is also fast'); SELECT id FROM notes WHERE MATCH(body) AGAINST ('go') ORDER BY id;

Result:

Result

(0 rows)

sql SELECT @@innodb_ft_min_token_size AS min_word_length, @@ft_min_word_len AS myisam_min_word_len;

Result:

min_word_lengthmyisam_min_word_len
34

The setting is read at server start, so you change it in my.cnf, restart, and rebuild the index (OPTIMIZE TABLE or drop and recreate).

50% Rule and Small Tables

In natural language mode, a word that is in more than half of the rows is treated as too common and ignored. This surprises people who test with tiny tables where every row contains the word. Boolean mode does not have this rule.

Relevance Beats LIKE, But Know the Limits

  • Matches whole words (and prefixes with *), not arbitrary substrings.
  • Languages without spaces (Chinese, Japanese) need the ngram parser: FULLTEXT (body) WITH PARSER ngram.
  • No fuzzy matching or typo tolerance. Large search products (OpenSearch, Elasticsearch, Meilisearch) add that.
  • Inserts into large indexed tables are a little slower.

Common Beginner Mistakes

MistakeWhat happensFix
MATCH columns differ from the index columnsError 1191List exactly the indexed columns
Testing on 3 rows in natural modeNo results (50% rule)Use more data or boolean mode
Searching words shorter than 3 charactersNo hitsChange the token size or use LIKE
Expecting substring matchesMissing resultsUse prefix *, or ngram
Searching an ENGINE=MyISAM table in new designsOlder engine, no transactionsUse InnoDB

Practice

  1. Create a FULLTEXT index on title and body and search for a word.
  2. Rank results with MATCH ... AGAINST in the ORDER BY.
  3. Use boolean mode to find posts with +mysql but -replication.
  4. Check the minimum token size on your server.

Conclusion

A FULLTEXT index lets MATCH ... AGAINST search by word with ranking. Use boolean mode operators for control, remember stopwords, short words and the 50% rule, and move to a search engine when you need fuzzy matching.

Quick Summary: FULLTEXT, MATCH AGAINST, natural language, boolean mode, stopwords, ngram.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators