Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL TINYINT(1) versus BIT(1)

Tags:

mysql

bit

tinyint

Please enlighten me...

Which data type consumes the smallest, TINYINT(1) or BIT(1)?

I know that TINYINT(1) and BIT(1) is considered the same according to majority of answers here.

Doesn't TINYINT(1) accepts 0-9 while BIT(1) can only 1 or 0. From the looks of it TINYINT uses larger storage because it can accept 2-9 while BIT only 1 and 0.

like image 335
gptimajo Avatar asked Sep 28 '22 02:09

gptimajo


1 Answers

A TINYINT will always have a size of one (1) byte. And accept values between -128 and 127 (if signed).

The number you put in the brackets is for display purposes.

A BIT(1) on the other hand only take one bit in storage but needs to be aligned to whole bytes, meaning that if you only have one BIT(1) column, one byte is used, but if you have multiple they can be placed in the same byte.

like image 99
Krycke Avatar answered Oct 05 '22 08:10

Krycke