LENGTH() in MySQL — How It Works
What the MySQL LENGTH() function does, with an example.
Published October 18, 2026
LENGTH() returns the length of a string in bytes; CHAR_LENGTH() returns it in characters. They differ for multi-byte text such as emoji or accented letters.
How it works
Use CHAR_LENGTH for 'how many characters'.
Try it in MySQL
SELECT LENGTH('hello')
5
SELECT LENGTH('é')
2
SELECT CHAR_LENGTH('é')
1
Practical examples
Example 1
SELECT LENGTH('hello');
-- 5Example 2
SELECT LENGTH('é');
-- 2Example 3
SELECT CHAR_LENGTH('é');
-- 1Use it in a real query
SELECT id, LENGTH('hello') AS result
FROM your_table
LIMIT 10;Common mistakes
- Using LENGTH to count characters in UTF-8 text.
- Expecting NULL to return 0 (it returns NULL).
- Validating input length with bytes instead of characters.
Key takeaways
- LENGTH() in one line: LENGTH() returns the length of a string in bytes; CHAR_LENGTH() returns it in characters.
- Try queries in a test database first.
- Check NULL handling and data types.
FAQ
LENGTH vs CHAR_LENGTH?
LENGTH counts bytes; CHAR_LENGTH counts characters.
Does LENGTH() work in other databases?
Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.