If you’ve ever tried Vietnamese full-text search in MySQL, you probably got garbage results — missing words, incomplete matches, the works. I ran into this on a project and spent a while figuring out why. Turns out MySQL’s defaults just aren’t built for Vietnamese.
What’s Wrong Out of the Box
MySQL ships with a few settings that kill Vietnamese search:
- Words shorter than 3 characters don’t get indexed. Vietnamese has tons of meaningful 1-2 character words.
- The default stopword list filters out “common” words — but it was designed for English, so it can strip out important Vietnamese terms.
- No built-in Vietnamese word segmentation. Vietnamese is tonal and multi-syllabic, so MySQL’s tokenizer doesn’t handle it well.
The Fix
Add these to your my.cnf:
ft_min_word_len=1
ft_stopword_file=""
innodb_ft_enable_stopword="OFF"
innodb_ft_min_token_size=1
What each one does:
ft_min_word_len=1— index words starting from 1 character.ft_stopword_file=""— kill the default stopword list entirely.innodb_ft_enable_stopword="OFF"— same thing but for InnoDB.innodb_ft_min_token_size=1— let InnoDB index short words too.
After Changing Config
You need to rebuild your full-text indexes:
ALTER TABLE ten_bang DROP INDEX ten_index;
ALTER TABLE ten_bang ADD FULLTEXT(ten_cot);
Then query like normal:
SELECT * FROM ten_bang WHERE MATCH(ten_cot) AGAINST('tìm kiếm tiếng việt' IN NATURAL LANGUAGE MODE);
Things to Keep in Mind
- Setting min word length to 1 means bigger indexes and potentially slower performance on huge tables. Trade-off worth making for Vietnamese though.
- MySQL still can’t do proper Vietnamese word segmentation. Compound words without spaces won’t search perfectly. If you need that level of accuracy, look into tokenization libraries at the app layer.
- For production systems with heavy search traffic, consider Elasticsearch or Meilisearch instead — they handle Vietnamese much better out of the box.