LIKE in MySQL — How It Works

What the MySQL LIKE function does, with an example.

Published October 23, 2026

LIKE matches strings using patterns: % matches any sequence and _ matches a single character. It is the basic text search operator.

How it works

A pattern with a leading % cannot use an index; for real text search use FULLTEXT indexes.

Try it in MySQL

SELECT * FROM users WHERE name LIKE 'A%'
starts with A
SELECT * FROM users WHERE email LIKE '%@gmail.com'
gmail users
SELECT * FROM t WHERE code LIKE 'A_1'
A?1

Practical examples

Example 1

SELECT * FROM users WHERE name LIKE 'A%';
-- starts with A

Example 2

SELECT * FROM users WHERE email LIKE '%@gmail.com';
-- gmail users

Example 3

SELECT * FROM t WHERE code LIKE 'A_1';
-- A?1

Use it in a real query

SELECT * FROM users WHERE name LIKE 'A%';

Common mistakes

  • Leading wildcards causing full table scans.
  • Forgetting to escape % and _ (use ESCAPE).
  • Expecting case-sensitivity (depends on collation).

Key takeaways

  • LIKE in one line: LIKE matches strings using patterns: % matches any sequence and _ matches a single character.
  • Try queries in a test database first.
  • Check NULL handling and data types.

FAQ

Search many words?

Use a FULLTEXT index and MATCH ... AGAINST.

Does LIKE work in other databases?

Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.

More SQL articles