本文介绍了MySQL类型文本的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在创建一个用于发送私人消息的表单,并希望设置一个textarea的 maxlength 值,该值适合文本的最大长度字段在我的MySQL数据库表。 如果很多,我可以在数据库文本类型字段中指定长度,就像使用varchar一样吗?解决方案查看最大数字: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html TINYBLOB,TINYTEXT L + 1字节,其中L BLOB,TEXT L + 2字节,其中L MEDIUMBLOB,MEDIUMTEXT L + 3字节,其中L LONGBLOB,LONGTEXT L + 4字节,其中L L是文本字段中的字节数。因此,文本的字符的最大数量为2 16 -1(使用单字节字符)。 UTF-8 / MultiByte编码:使用MultiByte编码,每个字符可能消耗超过1字节的空间。对于UTF-8,每个字符的空间消耗在1到4个字节之间。 I'm creating a form for sending private messages and want to set the maxlength value of a textarea appropriate to the max length of a text field in my MySQL database table. How many characters can a type text field store?If a lot, would I be able to specify length in the database text type field as I would with varchar? 解决方案 See for maximum numbers:http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.htmlTINYBLOB, TINYTEXT L + 1 bytes, where L < 2^8 (255 Bytes)BLOB, TEXT L + 2 bytes, where L < 2^16 (64 Kibibytes)MEDIUMBLOB, MEDIUMTEXT L + 3 bytes, where L < 2^24 (16 Mebibytes)LONGBLOB, LONGTEXT L + 4 bytes, where L < 2^32 (4 Gibibytes)L is the number of bytes in your text field. So the maximmum number of chars for text is 216-1 (using single-byte characters). Means 65 535 chars(using single-byte characters).UTF-8/MultiByte encoding: using MultiByte encoding each character might consume more than 1 byte of space. For UTF-8 space consumption is between 1 to 4 bytes per char. 这篇关于MySQL类型文本的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-26 07:18
查看更多