Home > Back-end >  What does N in varchar(N) actually mean in MySQL? [duplicate]
What does N in varchar(N) actually mean in MySQL? [duplicate]

Time:09-27

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?

CodePudding user response:

N defines the size of the string in bytes.

To hold unicode values You need to choose a utf8_* character set for your table. varchar is fine for unicode values. Text and memo fields will then automatically be stored in UTF-8. More infos here

CodePudding user response:

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

  • Related