Function Reference

CHAR_LENGTH

Returns the length of a string in characters.

MySQL 8.1
CHAR_LENGTH(str)

Parameters

strVARCHAR
String to measure

Return value

An integer number of characters, not bytes

Examples

Characters versus bytes

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

Products with a long name

MySQL 8.1
SELECT good_name,
	CHAR_LENGTH(good_name) AS name_length
FROM Goods
WHERE CHAR_LENGTH(good_name) > 15;
good_namename_length
music school fee16
english school fee18
airsoft game session20
netflix subscription20

Details

LENGTH counts bytes, not characters. In utf8mb4 a Cyrillic letter takes 2 bytes, so in the example LENGTH returns 12, while CHAR_LENGTH returns 6.

See also