Mysql 中的Text字段的范围
text:存储可变长度的非Unicode数据,最大长度为2^31-1个字符。text列不能有默认值,存储或检索过程中,不存在大小写转换,后面如果指定长度,不会报错误,但是这个长度是不起作用的,意思就是你插入数据的时候,超过你指定的长度还是可以正常插入。
mysql中text 最大长度为65,535(2的16次方–1)字符的TEXT列。
如果你觉得text长度不够,可以选择
MEDIUMTEXT最大长度为16,777,215。
LONGTEXT最大长度为4,294,967,295
Text主要是用来存放非二进制的文本,如论坛帖子,题目,或者百度知道的问题和回答之类。
需要弄清楚的是text 和 char varchar blob这几种类型的区别。
详细用法可查看手册
http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#column-type-overview
mysql 修改 text字段长度_mysql的text字段长度?mysql数据库中text字段长度不够的问题…
类型是可变长度的字符串,最多65535个字符;
可以把字段类型改成MEDIUMTEXT(最多存放16777215个字符)或者LONGTEXT(最多存放4294967295个字符).
MySQL supports 4 TEXT field types (TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT) and this post looks at the maximum length of each of these field types.
MyISAM tables in MySQL have a maximum size of a row of 65,535 bytes, so all the data in a row must fit within that limit. However, the TEXT types are stored outside the table itself and only contribute 9 to 12 bytes towards that limit. (For more information about this refer to the MySQL Manual - Data Storage Requirements chapter). TEXT data types are also able to store much more data than VARCHAR and CHAR text types so TEXT types are what you need to use when storing web page or similar content in a database. The maximum amount of data that can be stored in each data type is as follows: TINYTEXT256 bytes
TEXT65,535 bytes~64kb
MEDIUMTEXT 16,777,215 bytes~16MB
LONGTEXT4,294,967,295 bytes~4GB
In most circumstances the TEXT type is probably sufficient, but if you are coding a content management system it’s probably best to use the MEDIUMTEXT type for longer pages to ensure there are no issues with data size limits.
汉字在utf8mb4中占用几个字符
答:3个
MySQL官方手册中对于utf8mb4的解释是
现有数据库版本默认的utf8都为utf8mb3,注意其中所说的"相同的长度"。
所以在utf8mb4下,英文占用1个字节,一般汉字占3个字节,emoji表情占4个字节。
关于代码插入emoji表情报错,请检查 表编码 和 数据库连接 编码是否同时为utf8mb4。
结论:数据库和表都设置为utf8mb4。