Skip to content
sang.id.vn
Go back

Configure MySQL for Full-Text Search with Vietnamese

Tiếng Việt

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:

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:

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


Share this post on:

Previous Post
NGINX Notes — Things I Keep Coming Back To
Next Post
Make PHP Enforce Strict Types