Disclaimer: this post takes into consideration that strict mode is enabled on the server
VARCHAR and CHAR are
used to store strings. VARCHAR stores varying length
and CHAR always use the same exact size no matter
the size of the string. For example, CHAR(4) will always
store 4 bytes, whereas VARCHAR(4) will store up to 5
bytes. See documentation.
When we create a table like this one:
We put inside the parentheses the length of the field in
characters for the VARCHAR field. However, the
maximum size in bytes of the field will depend on the
CHARSET and COLLATION of the table. You
can also specify a different collation for a column.
For instance:
- latin1: 1 to 2 bytes per …