Name

LENGTH( )

Synopsis

LENGTH(string)

This function returns the number of bytes contained in a given string. Note that there are eight bits to a byte and there is one byte to a letter. OCTET_LENGTH() is an alias.

SELECT LENGTH('test') AS 'Number of Bytes';
+-----------------+
| Number of Bytes |
+-----------------+
|               4 |
+-----------------+

There are four letters in the word “test,” so the string examined is composed of four bytes.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.