Home > Net >  MySQL: varchar(64) vs. varchar(255), is there a difference for small strings?
MySQL: varchar(64) vs. varchar(255), is there a difference for small strings?

Time:11-18

Is there a difference when storing the string "hello" in a column of varchar(64) or varchar(255), assuming all environments(engine, charset .etc) are the same? (For example, the engine automatically allocate space for maximum length or padding up string)

To give some context, I have a case where I will store texts of length less than 64 for 99% of time while there will be text between length 64 and 255 for the remaining 1% of time .

Now if there is a significant overhead for varchar(255) then I will create a separate table for the long string case but if there isn't any overhead then I will just declare the column as varchar(255).

The closest answer I could find is the following question: How much real storage is used with a varchar(100) declaration in mysql?

However it did not answer my question precisely.

CodePudding user response:

No. Some people just use VARCHAR(255) for all short strings columns. For CHAR columns, all strings will padded with blanks up to the defined length.

  • Related