42

What's the max length/number of chars in a mediumtext mysql field?

Ali
  • 261,656
  • 265
  • 575
  • 769

2 Answers2

63

While I think this question should have been answered by a simple Google search, I can't, realistically, vote to close under any of the existing options. As such I choose to offer an answer instead, in order that, hopefully, it won't be asked again and, if it is, subsequent questions may be closed as duplicates.

The maximum length of a 'mediumtext' field, in MySQL, is:

A string with a maximum length of 16,777,215 characters.

Or, according to the docs:

L + 3 bytes, where L < 224

Petah
  • 45,477
  • 28
  • 157
  • 213
David Thomas
  • 249,100
  • 51
  • 377
  • 410
2

You cannot make an assumption that 16,777,215 characters can be stored in a medium-text field. This depends on the character encoding, in some instances a single character can be comprised of more than one byte (wide characters or Unicode characters).

Checking the actual size in bytes remains the safest bet, especially if you want to develop a localized application.

Gerrit Brink
  • 977
  • 3
  • 15
  • 26
  • As long as you have the right encoding type on your column, text field lengths should be consistent no matter what encoding you use. Checking bytes is only useful for BLOBs. – Deji Jun 21 '16 at 09:27
  • http://dev.mysql.com/doc/refman/5.7/en/string-type-overview.html - A TEXT column with a maximum length of 255 (28 − 1) characters. The effective maximum length is less if the value contains multibyte characters. – Gerrit Brink Jun 21 '16 at 13:25
  • As I said, it depends on the encoding type. – Deji Jun 21 '16 at 14:18