What is the datatype to store boolean value in MySQL? [duplicate] What is the datatype to store boolean value in MySQL? [duplicate] mysql mysql

What is the datatype to store boolean value in MySQL? [duplicate]


MySQL have BOOL and BOOLEAN, but they are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true. I guess someone at MySQL thought about it and decided TINYINT(1) is the preferred way to go. I've always used that myself.

There's some more info in this similar question: What is the difference between BIT and TINYINT in MySQL?


BIT doesn't work the way you think it does, It is generally used for storing bitfields and BIT(M) takes about (M+7)/8 (integer arithmetic) bytes of storage. Using BIT(1) takes a whole byte anyway, the same as TINYINT so don't worry about it.

In case you are interested, the storage requirements for various types are located here.


According to the MySQL manual you can use bool and boolean which are at the moment aliases of tinyint(1):

Reference: Which MySQL data type to use for storing boolean values

Similar to MS SQL's Bit Datatype:

0 = False    1 = True