Function Reference

LENGTH

Returns the length of a string in bytes.

MySQL 8.1
LENGTH(str)

Parameters

strVARCHAR
String to measure

Return value

An integer length in bytes, not characters

Examples

Length of a string

MySQL 8.1
SELECT LENGTH('sql-academy');
LENGTH('sql-academy')
11

Bytes and characters in Cyrillic

MySQL 8.1
SELECT LENGTH('привет') AS bytes,
	CHAR_LENGTH('привет') AS chars;
byteschars
126

Details

In utf8mb4 a Latin letter or a digit takes 1 byte, a Cyrillic letter takes 2 bytes, the € sign takes 3 and an emoji takes 4. To count characters, use CHAR_LENGTH. In PostgreSQL, the function with the same name LENGTH counts characters, not bytes, so the result for Cyrillic changes when a query is moved between the DBMSs.

See also

Where to learn