Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL data type: Text,,, Erroring: Data Too Long

I have a field as follows in MySQL: Type: Text Length: 0 Decimals: 0

And when I try to insert data around the size of 4 pages of MS Word, Coldfusion errors with: Data Too Long from the DB.

I thought TEXT data type was able to expand and handle this size of data? What am I missing and what can I do?

like image 243
AnApprentice Avatar asked Apr 03 '10 00:04

AnApprentice


People also ask

How long can TEXT be in mysql?

TEXT: 65,535 characters - 64 KB The standard TEXT data object is sufficiently capable of handling typical long-form text content. TEXT data objects top out at 64 KB (expressed as 2^16 -1) or 65,535 characters and requires a 2 byte overhead.

How do I fix a data too long for a column?

That error message means you are inserting a value that is greater than the defined maximum size of the column. The solution to resolve this error is to update the table and change the column size.

What is TEXT data type in mysql?

The four TEXT types are TINYTEXT , TEXT , MEDIUMTEXT , and LONGTEXT . These correspond to the four BLOB types and have the same maximum lengths and storage requirements.

What is difference between TEXT and Longtext in mysql?

TEXT has a maximum length of 65,535 bytes—the same as VARCHAR. MEDIUMTEXT has a maximum length of about 16 megabytes. LONGTEXT has a maximum length of about 4 gigabytes.


2 Answers

The type TEXT is limited to 2^16 bytes, or 65536 bytes. Try using the type LONGTEXT instead. It can hold values up to 2^32 bytes in length.

like image 95
Mark Byers Avatar answered Sep 18 '22 08:09

Mark Byers


Text extracted from:

MySQL 5.1 Reference Manual :: 10 Data Types :: 10.1 Data Type Overview :: 10.1.3 Overview of String Types

TEXT[(M)] [CHARACTER SET charset_name] [COLLATE collation_name]  A TEXT column with a maximum length of 65,535 (2^16 – 1) characters. 

The effective maximum length is less if the value contains multi-byte characters. Each TEXT value is stored using a two-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.

I think you'd better use BLOB for that column.

MySQL 5.0 Reference Manual :: 10 Data Types :: 10.4 String Types :: 10.4.3 The BLOB and TEXT Types

like image 20
Leniel Maccaferri Avatar answered Sep 22 '22 08:09

Leniel Maccaferri