MySQL char vs. int

后端 未结 4 1396
情话喂你
情话喂你 2021-01-22 09:55

I\'m currently having a discussion in my class about the datatypes char and int in MySQL. We have a phone number of 8 individual numbers. However, we c

4条回答
  •  清歌不尽
    2021-01-22 10:45

    If you have a fixed size then you can use char(8) -> 8B , mysql works much faster with fixed size fields, but if you chose int -> 4B you will save space and also if you will have a index on that field it will work faster then the char.

    You can do a simple benchmark to test the speed of writes and reads using char(8) and int

    There is no point in using variable length type like varchar or varbinary if you have a fixed size because performance will decrease

提交回复
热议问题