-2

What does N in varchar(N) actually mean in MySQL?

Is it the length of the string in characters or the maximum size in bytes, and can varchar in modern MySQL hold Unicode values? Or do I need to choose a different data type? If varchar supports Unicode, do I have to take into account that a Unicode character can be larger than 1 byte?

jarlh
  • 42,561
  • 8
  • 45
  • 63
Nethrenial.
  • 558
  • 1
  • 5
  • 15

1 Answers1

1

N is the number of characters, and character is larger than 1 byte usually. https://dev.mysql.com/doc/refman/8.0/en/char.html

utf8mb4 is a good choose to handle emoji. The is a little trap with utf8mb3 that is used some time by default that is not really UTF8 but a subset.

https://dev.mysql.com/doc/refman/8.0/en/charset-unicode.html

Mr_Thorynque
  • 1,749
  • 1
  • 20
  • 31