On a remote server I’m saving text (967 537 characters) from textarea to MySQL database, column with type of TEXT.
Only around 63 748 characters are saved.
Also, in phpMyAdmin I’m getting the following error when doing UPDATE:
Warning: #1265 Data truncated for column 'content' at row 1
Since I don’t have access to change config files myself, it would be good to know what should be changed to fix this problem before I request for it.
Versions:
PHP 5.2.14
MySQL 5.0.96
Apache 2.2.12
MySQL config:
max_allowed_packet = 52428800
net_buffer_length = 8192
PHP ini:
post_max_size = 32M
Apache:
suhosin.post.max_value_length = 1000000
On localhost, everything works just fine.
Type
TEXTis too small (it can only hold up to around 64K, as you discovered). You can useMEDIUMTEXTto reach 16M, orLONGTEXTto get even more. Given storage requirements (one extra byte for every row), if there’s the slightest risk of ever exceeding 16M, go withLONGTEXT.But I think you should question why you are storing data in the DB. Unless it is an indirect requirement of the platform (e.g. it’s easier to use an ORM, while file storage would need an ad hoc column data driver), or you want to make use of full text indexing functions, it might be more convenient to store data as separate files and only store the file name in the database (or you might use
tablename_primarykeyvalue.htmlas file name, thus saving also file name storage requirements).The “separate storage” method complicates data retrieval and backups. On the other hand, backups will be smaller and faster, disk usage will be lower, and if your security model allows it, you could allow direct access to the files bypassing the database altogether: for example if you’re storing blog posts, you can retrieve them through AJAX, reducing database load and exploiting browser caching strategies (also, on some platforms, you can directly serve compressed files, thereby boosting speed and saving CPU).
This post Do very large fields have a negative effect on MySQL databases? advocates MySQL TEXT storage, but also presents some considerations on why you might not want to.
UPDATE
Danger, Will Robinson! There’s no way it can work on
localhost, unless your development and production databases are not synchronized. I.e., you haveMEDIUMTEXTon localhost andTEXTon the remote. So the question is, what else could be different between the two databases? While not related to your question, it’s something you definitely want to check!