PHP and MYSQL maximum variable length?

2019-07-23 20:39发布

问题:

I'm trying to do an INSERT into a mysql db and it fails when any of the values are longer than 898 characters. Is there somewhere to get or, better, set this maximum value? I'll hack the string into chunks and store 'em in separate rows if I must, but I'd like to be able to insert up to 2k at a time.

I'm guessing this is php issue as using LONGTEXT or BLOB fields should be more than enough space in the db.

Thanks.

回答1:

Side Note:

When you get into working with large blobs and text columns, you need to watch out for the MySQL max_allowed_packet variable. I believe it defaults to at least 1M.



回答2:

I'm assuming this is a varchar column you're trying to insert into? If so, I assume the maximum length has been set to 898 or 900 or something like that.

In MySQL 5 the total row size can be up to 65,536 bytes so a varchar can be defined to whatever size keeps the total row size under that.

If you need larger use text (65,536) or longtext (4 billion?).