11
votes

Why do so many developers set varchar to 254 and not 255 when creating MySQL tables?

Proof that this happens: mysql varchar 254

2
Maybe some are scared going really to the limit! Living on the edge! :) - juergen d
@Jason_vorhees: I have also seen varchar(254) and wondered what the decision making process was for that. I write it off as "there was none; it's arbitrary dumbness / negligence", but I am open to being wrong. Interested to hear an answer to this. - tenfour
I am not form those developers - user319198
149000 results vs 1190000 for varchar(255) :) - Maxim Krizhanovsky
@tenfour may be its a chance that i never seen maximum 254 limit in any of table but i didnot think that there could be ever any valid reason for it at all. Its just a wild selection of some person without thinking. - Ankit Sharma

2 Answers

13
votes

Your Google query gave you the hints already. One of the first hits is this:

https://www.vbulletin.com/forum/project.php?issueid=32655

It basically says, that FULLTEXT indexes on VARCHAR(255) require twice the space of a VARCHAR(254) FULLTEXT index. And some more other bloat on top of that.

I think this is far more important than saving one byte in the data table.

6
votes

varchar fields require n+1 bytes for fields less than or equal to 255 and required n+2 bytes for fields > 255

http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html

It should be set to 255, I'm assuming developers think they will save an extra byte from 254, but 255 is the standard