Stop Using LIKE '%...%' for Search Category: Database / MySQL

Searching is a core feature of almost every app. The first instinct is often to use the LIKE operator with wildcards.

T Theodoros Kafantaris December 07, 2025 1 min read
Stop Using LIKE '%...%' for Search Category: Database / MySQL

Searching is a core feature of almost every app. The first instinct is often to use the LIKE operator with wildcards.

Code
                    -- 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.

Code
                    -- 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?

  1. Speed: It uses an inverted index (instant lookup).

  2. Relevance: It can sort results by how well they match (not just yes/no).

Share this post

Back to Blog

Let's talk

Stay Curious. Stay Inspired.

Join our community of thinkers, developers, and lifelong learners. Explore ideas that challenge and inspire you to think differently.