3

I'm using MySql 5.5.37. I have an InnoDB table with the following column

| MESSAGE  | text        | YES  |     | NULL              |       |

I'm noticing errors in our logs (we use Hibernate v5) that resemble

Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'MESSAGE' at row 1
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4094) [mysql-connector-java-5.1.22-bin.jar:]
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028) [mysql-connector-java-5.1.22-bin.jar:]
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490) [mysql-connector-java-5.1.22-bin.jar:]
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651) [mysql-connector-java-5.1.22-bin.jar:]
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734) [mysql-connector-java-5.1.22-bin.jar:]
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155) [mysql-connector-java-5.1.22-bin.jar:]
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458) [mysql-connector-java-5.1.22-bin.jar:]
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375) [mysql-connector-java-5.1.22-bin.jar:]
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359) [mysql-connector-java-5.1.22-bin.jar:]
        at org.jboss.jca.adapters.jdbc.CachedPreparedStatement.executeUpdate(CachedPreparedStatement.java:115)
        at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204) [hibernate-core-5.1.5.Final.jar:5.1.5.Final]

My question is, what is the maximum length (in characters) of a TEXT column?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • 1
    Did you make any attempt to search for the answer? The duplicate question title is almost identical to yours. – Barmar Aug 02 '17 at 20:39
  • 1
    The max length is 64K _bytes_, which is somewhere between 16K and 64K `utf8mb4` _characters_. Switch to `MEDIUMTEXT` to increase the limit. – Rick James Aug 13 '17 at 21:03

1 Answers1

5

This question is about characters; the proposed "dup" is about bytes. So, I reopened it.

The max length if a TEXT column is 64K bytes, which is somewhere between 16K and 64K utf8mb4 characters.

Of you are using latin1, 64K. If utf8, 64K/3. Etc.

Switch to MEDIUMTEXT to increase the limit to 16M (or 16M/4, etc).

Rick James
  • 135,179
  • 13
  • 127
  • 222