BIT MySQL Data Type

The BIT data type is used for bit value. Bit value range will be 1 to 64 bytes. It stores values in binary form (0 and 1).

The syntax for BIT data type will be BIT(M). Here BIT represents the value that will be stored in binary formats. and M can be range from 1 to 64. And the default count is 1 when no digit is specified within BIT ().

BIT value literally called b’value or 0bvalue notation. Here value is binary (0,1) value. Leading 0b is case-sensitive.    

We use BIN() Mysql function in the SELECT query for getting proper data of BIT Data Type. Since the bit value literal started with zeros, it omitted the preceding zeros while displaying the output. So, avoiding this situation, we will use the Mysql function LPAD() before BIN() function.


CREATE TABLE employee(

employee_name VARCHAR(255),

attendance BIT(5),

department VARCHAR(255)


The query of this table:-

SELECT employee_name, LPAD(BIN(attendance)), department FROM employee;

Note:- The maximum combined size of all BIT columns used in a given NDB table must not exceed 4096 bits.

Share with:

Leave a Reply

Connect with: