MySQL best way to store a large WYSIWYG field (e.g., 140668 characters)

Viewed 162

I am using the the Summernote WYSIWYG editor in a HTML and when I past a picture into it the length of the data blows out to 140668 (activityDescription.length()). I am currently using MySQL varchar(10000) utf8_unicode_ci to store the data. The varchar() data length restrictions are 65535 characters shared amongst all columns. This does not allow enough to store that data. What is the best way to store this data please?

1 Answers

You can store it in a MEDIUMTEXT.

VARCHAR and TEXT can store up to 64KB (216) in bytes (not in characters). If you use a multi-byte character set like utf8 or utf8mb4, the maximum number of characters may be less (these character sets use a variable number of bytes per character).

MEDIUMTEXT can store up to 16MB. Again, multi-byte character sets mean the maximum number of characters might be less than 224.

LONGTEXT can store up to 4GB (232 bytes) in theory, but it may not be easy or possible to get data that long into that column because the largest value for max_allowed_packet_size is 1GB.

Read more: https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html#data-types-storage-reqs-strings

Related