MySQL, better to insert NULL or empty string?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
NULL and '' do not mean the same thing in MySQL. NULL means "unknown, missing, or not applicable," while the empty string means "known value, and that value is an empty string." The better choice depends on your data semantics, not on a blanket performance rule.
If your application treats those meanings differently, your schema should too. Using the wrong one makes queries, constraints, and business logic much harder to reason about later.
What NULL Means
NULL is not a string. It represents the absence of a value.
That changes query behavior:
You cannot reliably test NULL with ordinary equality operators:
Instead, use IS NULL and IS NOT NULL.
What the Empty String Means
The empty string is a real string value of length zero:
This says the column was given a value and that value is intentionally empty. That is very different from "we do not know the value" or "the field does not apply."
Choose Based on Semantics
Use NULL when:
- the value is unknown,
- the value has not been provided,
- the field does not apply to this row.
Use '' when:
- the empty string is a legitimate business value,
- your application explicitly distinguishes empty text from missing text,
- the user intentionally entered a blank value and that distinction matters.
For many optional text columns, NULL is the more truthful representation of missing data.
Query and Aggregate Differences
The distinction affects aggregates and predicates:
This counts only non-NULL values. Empty strings are still counted, because they are real values.
Likewise:
ignores NULL scores, but there is no equivalent concept of an "empty numeric value" for a number column.
That is why choosing between NULL and '' changes not just storage, but also query meaning.
Application Logic Gets Cleaner When Semantics Are Clear
Suppose a middle_name column is optional. If a user simply did not provide one, NULL is usually clearer. If you instead store '', every query and every downstream service has to remember that empty string also means "missing."
That creates accidental complexity:
A cleaner schema often avoids needing both cases to mean the same thing.
That also helps application code. If one representation means "missing" and the other means "explicitly empty," your validation, API responses, and analytics can stay consistent instead of encoding the same absence in two different ways.
That consistency pays off for years.
Common Pitfalls
- Using
''andNULLinterchangeably even though the application means different things by them. - Writing
= NULLinstead ofIS NULL. - Storing empty strings as a placeholder for "unknown" and then complicating every query later.
- Assuming the decision is mostly about performance. It is primarily about data semantics.
- Forgetting that aggregates treat
NULLdifferently from ordinary values.
Summary
- '
NULLmeans no value;''means a real string value of length zero.' - Choose based on business meaning, not habit.
- Use
NULLfor unknown, missing, or not-applicable data. - Use
''only when empty text is a legitimate stored value. - Clear semantics make queries, validation, and reporting much easier.
Related reading
- MySQL between clause not inclusive?
- MySQL C async methods doesn't work?
- MySQL Cannot Add Foreign Key Constraint
- MySQL Cannot drop index needed in a foreign key constraint
- MySQL Can't create table errno 150
- MySQL case sensitive query
- mysql CHANGE MASTER TO command's MASTER_HOST's length limitation
- mysql check collation of a table

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.