Can't see MySQL BIT field value when using SELECT Can't see MySQL BIT field value when using SELECT mysql mysql

Can't see MySQL BIT field value when using SELECT


The reason why you can't see it in terminal is because bit values are non printable characters.

Lets insert following values:

INSERT INTO `my_table` (`ID`, `enabled`)VALUES (1,b'1'),(2,b'0');

Then select them to file:

mysql> SELECT * FROM my_table INTO OUTFILE '/tmp/my_table.txt' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

First lets view our /tmp/my_table.txtfile as plain text:

"1"," "
"2"," "

and then in hex view:

22 31 22 2C 22 01 22 0A 22 32 22 2C 22 00 22 0A

To be able to see those values you can simply CAST them in SELECT:

SELECT id, CAST(enabled AS UNSIGNED) AS enabled FROM my_table

And that will produce the following output:

+----+---------+| id | enabled |+----+---------+|  1 |       1 ||  2 |       0 |+----+---------+2 rows in set (0.00 sec)


Another way you can do it is

SELECT enabled+0 from my_table


the simplest way is ORD function:

SELECT ORD(`enabled`) AS `enabled` FROM `my_table`