MySQL InnoDB 存储引擎, utf8mb4 字符集, varchar(100)到底可以存多少个汉字

查看 77|回复 4
作者:vamilk3344   
beneo   
utf8mb4 是一种变长字符编码,可以用 1 到 4 个字节来表示一个字符,一般是 3 个字节。
dode   
汉字长度可能不一定
simonlu9   
100 个
chanyan   
For example, a VARCHAR(255) column can hold a string with a maximum length of 255 characters. Assuming that the column uses the latin1 character set (one byte per character), the actual storage required is the length of the string (L), plus one byte to record the length of the string. For the string 'abcd', L is 4 and the storage requirement is five bytes. If the same column is instead declared to use the ucs2 double-byte character set, the storage requirement is 10 bytes: The length of 'abcd' is eight bytes and the column requires two bytes to store lengths because the maximum length is greater than 255 (up to 510 bytes).
The effective maximum number of bytes that can be stored in a VARCHAR or VARBINARY column is subject to the maximum row size of 65,535 bytes, which is shared among all columns. For a VARCHAR column that stores multibyte characters, the effective maximum number of characters is less. For example, utf8mb4 characters can require up to four bytes per character, so a VARCHAR column that uses the utf8mb4 character set can be declared to be a maximum of 16,383 characters.
您需要登录后才可以回帖 登录 | 立即注册

返回顶部