How does MySql insert and query binary data mysql binary Mysql: bit-type query and insert mysql has a field type of bit. 1. How to insert it? It must be inserted: You can use the B 'value' symbol to write the field value. Value is a binary value written as 0 and 1.
mysql> create table an_bit (id bit(8));Query OK, 0 rows affected (0.00 sec)mysql> insert into an_bit values (11);Query OK, 1 row affected (0.00 sec)
Although it can be inserted, the actual inserted value is 11 (decimal), not 3 (decimal ).
mysql> insert into an_bit values (b’11′);Query OK, 1 row affected (0.00 sec)
This is the correct insert method. The inserted value is 3 (decimal) 2. How can I query it?
Mysql> select * from an_bit; + -- + | id | + -- + this is incorrect, and mysql> select id + 0 from an_bit is invisible; + -- + | id + 0 | + -- + | 11 | 3 | + -- + this is correct. You can see the decimal value. Mysql> select bin (id + 0) from an_bit; + ---- + | bin (id + 0) | + ---- + | 1011 | 11 | + ---- + This is the binary value mysql> select oct (id + 0) from an_bit; + ---- + | oct (id + 0) | + ---- + | 13 | 3 | + ---- + This is the octal value of mysql> select hex (id + 0) from an_bit; + ---- + | hex (id + 0) | + ---- + | B | 3 | + ---- + THIS IS THE hexadecimal value.