2

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.

How can I fixed this?

I'm using MySQL and PHP framework Laravel 5.1

Omega P
  • 197
  • 1
  • 20
  • I think you can get perfact Solution here .. http://stackoverflow.com/questions/6766781/maximum-length-for-mysql-type-text – Kumar Rakesh Aug 30 '16 at 04:28
  • This is also one of the things I truly HATE about MySQL. Not that it has limits, but that it silently accepts and truncates the data. It should fail to do the insert to keep data sane. It become worse if you save JSON or file data, as you will now be saving them corrupted with data loss. – Rahly May 01 '17 at 14:26

3 Answers3

3

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.

Sherif
  • 11,786
  • 3
  • 32
  • 57
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
zx485
  • 28,498
  • 28
  • 50
  • 59
zoore
  • 293
  • 5
  • 13
1

Instead of type -> TEXT ( 65535 characters ) use type -> MEDIUMTEXT ( witch can contain 16 Million Characters )

moolsbytheway
  • 1,152
  • 13
  • 20