Stop Using LIKE '%...%' for Search Category: Database / MySQL
Theodoros Kafantaris
Published on December 07, 2025
Searching is a core feature of almost every app. The first instinct is often to use the LIKE operator with wildcards.
-- The Performance Killer
SELECT * FROM articles WHERE content LIKE '%Laravel%';
The Problem: When you put a % at the start of the string (%Laravel), MySQL cannot use an index. It must scan every single character of every single row. As your table grows, your site crashes.
The Solution: Use MySQL's native Full-Text Search.
-- 1. Add a Full Text Index
ALTER TABLE articles ADD FULLTEXT(content);
-- 2. Search instantly
SELECT * FROM articles WHERE MATCH(content) AGAINST('Laravel');
Why use it?
-
Speed: It uses an inverted index (instant lookup).
-
Relevance: It can sort results by how well they match (not just yes/no).