Is it better to use BIT or BOOLEAN for YES / NOT values ​​in MySQL?

1) There is a column in my table that sets user privileges.

I want to have a 1/0 flag (yes / not, true / false, etc.) for my rights (for example: if the user is an admin or mod ...).

I've searched a lot, I'm still confused about the differences in boolean and bitwise in terms of resource requests to the DBMS. What's better?

I also found a lot of questions about plugged years, so I would like a new answer in case something has changed / improved.

2) Another question ...

I tried to use both of these types, and I saw that it is easy to check if the value is true or false using boolean, but I did not understand how to see the value of the BIT variable. I am my coloumn database. I put the values ​​1 or 0, but nothing is displayed with the bit variable echo.

So how can I see the meaning of the bits (I only need to use 1 or 0).

Thank you for your consultation!

+3


source to share


1 answer


Use TINYINT(1)

. This is what is commonly used for boolean values. Keep in mind that it allows values ​​outside of 1 and 0, so for consistency I would suggest using keywords TRUE

also FALSE

when inserting data into it, since they reflect 1

and 0

.



BOOL

and BOOLEAN

are just synonyms for TINYINT(1)

. BIT

on the other hand was synonymous TINYINT(1)

until 5.0.3.

+3


source







All Articles