Function Reference

OCTET_LENGTH

A synonym for LENGTH: returns the length of a string in bytes.

MySQL 8.1
OCTET_LENGTH(str)

Parameters

strVARCHAR
String to measure

Return value

An integer, the length in bytes; NULL for NULL

Examples

Bytes and Cyrillic characters

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

Size of names in bytes

MySQL 8.1
SELECT member_name,
	OCTET_LENGTH(member_name) AS bytes
FROM FamilyMembers
LIMIT 3;
member_namebytes
Headley Quincey15
Flavia Quincey14
Andie Quincey13

Details

Unlike LENGTH, a function with the same name also exists in PostgreSQL and counts bytes there too, so OCTET_LENGTH gives the same result in both DBMSs.

See also