Company
Date Published
Author
Brian Morrison II
Word count
927
Language
English
Hacker News points
None

Summary

VARCHAR is a variable-length data type for strings in MySQL, storing up to 65,535 characters. It allocates extra space with each value stored, depending on the character set used, and has an overhead of 1 or 2 bytes. CHAR is a fixed-length data type, right-padded with empty spaces to always store n characters, regardless of the string's length. Character sets affect storage space allocation when saving data. When using CHAR, trailing spaces are effectively lost and not returned in queries. The choice between VARCHAR and CHAR depends on the specific use case, such as needing more than 255 characters or fixed-length strings with known lengths.