I have a table post
:
我有一个桌子帖子:
field | type --------------------------------- id | int A_I P_K title | varchar(300) content | text
When I insert a row with content
more than 15k words, my database just save 10k words and I lost 5k words.
当我插入一个内容超过15k字的行时,我的数据库只保存了10k字,我丢失了5k字。
How can I fixed this?
我该如何解决这个问题?
I'm using MySQL and PHP framework Laravel 5.1
我正在使用MySQL和PHP框架Laravel 5.1
3 个解决方案
#1
3
If you read the MySQL docs on TEXT type—or any other data type—you can find the limitations of each type.
如果您阅读TEXT类型的MySQL文档或任何其他数据类型 - 您可以找到每种类型的限制。
For example, TEXT
specifically has a limit of around 65K, however this limit can be decreased depending on the character encoding (e.g. UTF-8 or other multibyte encodings), because it's calculated in bytes and not by character.
例如,TEXT具有约65K的限制,但是这个限制可以根据字符编码(例如UTF-8或其他多字节编码)而降低,因为它是以字节计算的,而不是按字符计算的。
A TEXT column with a maximum length of 65,535 (216 − 1) characters. The effective maximum length is less if the value contains multibyte characters. Each TEXT value is stored using a 2-byte length prefix that indicates the number of bytes in the value.
一个TEXT列,最大长度为65,535(216 - 1)个字符。如果值包含多字节字符,则有效最大长度会减少。每个TEXT值使用2字节长度前缀存储,该前缀指示值中的字节数。
An optional length M can be given for this type. If this is done, MySQL creates the column as the smallest TEXT type large enough to hold values M characters long.
可以为此类型提供可选长度M.如果这样做,MySQL会将列创建为最小的TEXT类型,其大小足以容纳M个字符长的值。
So if your requirements exceed these limits you should pick a type that is equipped to handle larger payloads, like MEDIUMBLOB
and LONGBLOB
, which can handle up to 16M and 4G repsectively.
因此,如果您的要求超出这些限制,您应该选择一种能够处理更大负载的类型,例如MEDIUMBLOB和LONGBLOB,它们可以处理高达16M和4G。
#2
2
Type of field stored in database, gives you something like space in "tiny" workshop, laboratory, "medium" factory, "long" like a a large factory.
存储在数据库中的字段类型,在“小”工作室,实验室,“中”工厂,“长”像一个大工厂,给你一些空间。
but choose wisely, because that "space" sometimes accupies much more resources than it is needed. Use Type of field for it's purpose.
但明智地选择,因为“空间”有时会比需要更多的资源。使用字段类型是为了它的目的。
Type | Maximum length
-----------+-------------------------------------
TINYTEXT | 255 (2^8 −1) bytes
TEXT | 65,535 (2^16−1) bytes = 64 KiB
MEDIUMTEXT | 16,777,215 (2^24−1) bytes = 16 MiB
LONGTEXT | 4,294,967,295 (2^32−1) bytes = 4 GiB
#3
1
Instead of type -> TEXT
( 65535 characters ) use type -> MEDIUMTEXT
( witch can contain 16 Million Characters )
而不是类型 - > TEXT(65535个字符)使用类型 - > MEDIUMTEXT(女巫可以包含1600万个字符)
#1
3
If you read the MySQL docs on TEXT type—or any other data type—you can find the limitations of each type.
如果您阅读TEXT类型的MySQL文档或任何其他数据类型 - 您可以找到每种类型的限制。
For example, TEXT
specifically has a limit of around 65K, however this limit can be decreased depending on the character encoding (e.g. UTF-8 or other multibyte encodings), because it's calculated in bytes and not by character.
例如,TEXT具有约65K的限制,但是这个限制可以根据字符编码(例如UTF-8或其他多字节编码)而降低,因为它是以字节计算的,而不是按字符计算的。
A TEXT column with a maximum length of 65,535 (216 − 1) characters. The effective maximum length is less if the value contains multibyte characters. Each TEXT value is stored using a 2-byte length prefix that indicates the number of bytes in the value.
一个TEXT列,最大长度为65,535(216 - 1)个字符。如果值包含多字节字符,则有效最大长度会减少。每个TEXT值使用2字节长度前缀存储,该前缀指示值中的字节数。
An optional length M can be given for this type. If this is done, MySQL creates the column as the smallest TEXT type large enough to hold values M characters long.
可以为此类型提供可选长度M.如果这样做,MySQL会将列创建为最小的TEXT类型,其大小足以容纳M个字符长的值。
So if your requirements exceed these limits you should pick a type that is equipped to handle larger payloads, like MEDIUMBLOB
and LONGBLOB
, which can handle up to 16M and 4G repsectively.
因此,如果您的要求超出这些限制,您应该选择一种能够处理更大负载的类型,例如MEDIUMBLOB和LONGBLOB,它们可以处理高达16M和4G。
#2
2
Type of field stored in database, gives you something like space in "tiny" workshop, laboratory, "medium" factory, "long" like a a large factory.
存储在数据库中的字段类型,在“小”工作室,实验室,“中”工厂,“长”像一个大工厂,给你一些空间。
but choose wisely, because that "space" sometimes accupies much more resources than it is needed. Use Type of field for it's purpose.
但明智地选择,因为“空间”有时会比需要更多的资源。使用字段类型是为了它的目的。
Type | Maximum length
-----------+-------------------------------------
TINYTEXT | 255 (2^8 −1) bytes
TEXT | 65,535 (2^16−1) bytes = 64 KiB
MEDIUMTEXT | 16,777,215 (2^24−1) bytes = 16 MiB
LONGTEXT | 4,294,967,295 (2^32−1) bytes = 4 GiB
#3
1
Instead of type -> TEXT
( 65535 characters ) use type -> MEDIUMTEXT
( witch can contain 16 Million Characters )
而不是类型 - > TEXT(65535个字符)使用类型 - > MEDIUMTEXT(女巫可以包含1600万个字符)