开发者

MySQL entry and space used

开发者 https://www.devze.com 2023-04-06 08:51 出处:网络
开发者_Go百科I have a MySQL table with one of the columns like\"varchar(255)\". Will the Database use 255bytes of space even if that column is empty? or only if it has some data and the amount of spac
开发者_Go百科

I have a MySQL table with one of the columns like "varchar(255)". Will the Database use 255bytes of space even if that column is empty? or only if it has some data and the amount of space used is proportional to the data?


every cell will take only the amount of space proportional to the data. http://dev.mysql.com/doc/refman/5.0/en/char.html


only if it has some data and the amount of space used is proportional to the data.


VARCHAR(M) takes N+1 bytes or more depending on the size of the data you're adding. A blank field (empty string) will still consume 1 byte (that is the +1 on the N+1) that is used to indicate where that field's data ends - so you have 1 byte for the terminator.

From MySQL's website:

VARCHAR(M), VARBINARY(M)    
    L + 1 bytes if column values require 0 – 255 bytes, 
    L + 2 bytes if values may require more than 255 bytes

where L is the length of your data. In your case, you'll be consuming (data length + 1) on your VARCHAR(255) field.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号