What's the max length/number of chars in a mediumtext mysql field?
2 Answers
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.
L + 3 bytes, where L < 224

- 45,477
- 28
- 157
- 213

- 249,100
- 51
- 377
- 410
-
4Edited to change to Community Wiki, since I'd feel bad earning any rep from this. @The Scrum Meister, thanks! I'll edit that in. – David Thomas Mar 08 '11 at 02:48
-
Note: You *must* set the max_allowed_packet to be greater than or equal to the number of bytes desired. Otherwise you will be stuck at the default max of 1048576 bytes. – ostler.c Oct 28 '13 at 23:34
-
1in case it helps, that is about 5500 pages of printed text according to wolfram. goo.gl/Qa0Q75 – johnsnails Mar 31 '14 at 01:27
-
1Google leads me here. – magallanes Sep 23 '17 at 23:13
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.

- 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
-