Omega P Omega P - 1 year ago 67
MySQL Question

Database can't save large content

I have a table


   field    |    type
id | int A_I P_K
title | varchar(300)
content | text

When I insert a row with
more than 15k words, my database just save 10k words and I lost 5k words.

How can I fixed this?

I'm using MySQL and PHP framework Laravel 5.1

Answer Source

If you read the MySQL docs on TEXT type—or any other data type—you can find the limitations of each type.

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.

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.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download