我有一张表post
:
field | type --------------------------------- id | int A_I P_K title | varchar(300) content | text
当我插入 content
超过 15k 字的行时,我的数据库只保存了 10k 字,而我丢失了 5k 字。
我该如何解决这个问题?
我正在使用 MySQL 和 PHP 框架 Laravel 5.1
最佳答案
如果您阅读 MySQL docs on TEXT type — 或任何其他数据类型 — 您可以找到每种类型的局限性。
例如,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.
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.
因此,如果您的要求超过这些限制,您应该选择能够处理更大负载的类型,例如 MEDIUMBLOB
和 LONGBLOB
,它们可以处理高达 16M 和 4G 的负载分别。
关于php - 数据库无法保存大内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39218496/