MySQL类型文本的最大长度

MySQL的TEXT类型字段可以存储不同数量的字符:TINYTEXT - 256字节,TEXT - 65,535字节,MEDIUMTEXT - 16,777,215字节,LONGTEXT - 4,294,967,295字节。若使用UTF8字符集,TEXT类型最多存储21,844个字符。对于多字节字符,存储长度会有所不同。不需要为TEXT类型指定长度,若需要更大存储空间,可使用MEDIUMTEXT或LONGTEXT。" 133541297,19673829,使用JavaScript修改HTML元素的类,"['前端开发', 'HTML', 'JavaScript']
摘要由CSDN通过智能技术生成

本文翻译自:Maximum length for MySQL type text

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. 我正在创建一个发送私人消息的表单,并希望设置一个textarea的maxlength值,该值适合我的MySQL数据库表中文text字段的最大长度。 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? 如果很多,我能否像在varchar中那样在数据库文本类型字段中指定长度?


#1楼

参考:https://stackoom.com/question/SOLd/MySQL类型文本的最大长度


#2楼

TINYTEXT: 256 bytes TINYTEXT:256字节
TEXT: 65,535 bytes 文字:65,535字节
MEDIUMTEXT: 16,777,215 bytes MEDIUMTEXT:16,777,215字节
LONGTEXT: 4,294,967,295 bytes LONGTEXT:4,294,967,295字节


#3楼

How many characters can a type text field store? 类型文本字段可以存储多少个字符?

According to Documentation You can use maximum of 21,844 characters if the charset is UTF8 根据文档如果字符集是UTF8,则最多可以使用21,844个字符

If a lot, would I be able to specify length in the db text type field as I would with varchar? 如果很多,我能否像在varchar中那样在db文本类型字段中指定长度?

You dont need to specify the length. 你不需要指定长度。 If you need more character use data types MEDIUMTEXT or LONGTEXT. 如果您需要更多字符使用数据类型MEDIUMTEXT或LONGTEXT。 With VARCHAR, specifieng length is not for Storage requirement, it is only for how the data is retrieved from data base. 对于VARCHAR,指定的长度不适用于存储要求,它仅适用于从数据库中检索数据的方式。


#4楼

Type       | Approx. Length     | Exact Max. Length Allowed
-----------------------------------------------------------
TINYTEXT   | 256 Bytes          |           255 characters
TEXT       |  64 Kilobytes      |        65,535 characters
MEDIUMTEXT |  16 Megabytes      |    16,777,215 characters
LONGTEXT   |   4 Gigabytes      | 4,294,967,295 characters

Note: If using multibyte characters (like Arabic letters where each character takes 2 bytes), the column "Exact Max. Length Allowed" will have different length. 注意:如果使用多字节字符(如阿拉伯字母,每个字符占2个字节),“允许的最大长度”列将具有不同的长度。 For example: if you use 2-bytes characters, the exact maximum length for TINYTEXT would be 127 characters. 例如:如果使用2字节字符,则TINYTEXT的确切最大长度为127个字符。 Basically, it's the number of bytes allowed -1. 基本上,它是允许-1的字节数。


#5楼

 TINYTEXT 256 bytes TEXT 65,535 bytes ~64kb MEDIUMTEXT 16,777,215 bytes ~16MB LONGTEXT 4,294,967,295 bytes ~4GB 

TINYTEXT is a string data type that can store up to to 255 characters. TINYTEXT是一种字符串数据类型,最多可以存储255字符。

TEXT is a string data type that can store up to 65,535 characters. TEXT是一种字符串数据类型,最多可以存储65,535字符。 TEXT is commonly used for brief articles. TEXT通常用于简短的文章。

LONGTEXT is a string data type with a maximum length of 4,294,967,295 characters. LONGTEXT是一种字符串数据类型,最大长度为4,294,967,295字符。 Use LONGTEXT if you need to store large text, such as a chapter of a novel. 如果您需要存储大型文本(例如小说的章节),请使用LONGTEXT


#6楼

TEXT is a string data type that can store up to 65,535 characters. TEXT是一种字符串数据类型,最多可以存储65,535个字符。 But still if you want to store more data then change its data type to LONGTEXT 但是,如果您想存储更多数据, LONGTEXT其数据类型更改为LONGTEXT

ALTER TABLE name_tabel CHANGE text_field LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL; ALTER TABLE name_tabel CHANGE text_field LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值