What's the difference between VARCHAR and CHAR in MySQL?
I am trying to store MD5 hashes.
CHAR is a fixed length field; VARCHAR is a variable length field. If you are storing strings with a wildly variable length such as names, then use a VARCHAR, if the length is always the same, then use a CHAR because it is slightly more size-efficient, and also slightly faster.
To give you an example, CHAR(10) is a fixed-length non-Unicode string of length 10, while VARCHAR(10) is a variable-length non-Unicode string with a maximum length of 10. This means the actual length will depend upon the data.
SQL varchar stores variable string length whereas SQL char stores fixed string length. This means SQL Server varchar holds only the characters we assign to it and char holds the maximum column space regardless of the string it holds.
The basic difference between Char and Varchar is that: char stores only fixed-length character string data types whereas varchar stores variable-length string where an upper limit of length is specified.
VARCHAR
is variable-length.
CHAR
is fixed length.
If your content is a fixed size, you'll get better performance with CHAR
.
See the MySQL page on CHAR and VARCHAR Types for a detailed explanation (be sure to also read the comments).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With