mysql bit is a "bit data" type. Its data has two values, 0 and 1, with a length of 1 bit. MySQL provides a BIT type that allows you to store bit values. Its "BIT( m)" can store up to m bits of value, with m ranging from 1 to 64.
The operating environment of this tutorial: Windows 10 system, mysql8 version, Dell G3 computer.
What type is mysql bit?
Bit is called a bit data type. Its data has two values: 0 and 1, and the length is 1 bit. When values other than 0 are entered, the system treats them as 1. This data type is often used as a logical variable to represent binary choices such as true, false, or yes or no.
A type of data saved in SQL Server, which can only store true/false. After the program reads the database, the expression is true or false, but the structure type saved in the database is 0 or 1. 1 means true, 0 means false.
SQL Server
Since the BIT type only has 0 and 1 or false and true, this situation only needs one Bit to represent it. SQL Server
The space occupied by the BIT type is related to the location of the table where the BIT type column is located. In some cases, the BIT occupies one byte. In some cases, the BIT actually occupies several bits (several BIT types). columns share one byte).
MySQL BIT data type:
MySQL provides a BIT type that allows you to store bit values. BIT(m) can store up to m bits of value, with m ranging from 1 to 64.
If omitted, the default value is 1. So the following statements are the same:
column_name BIT(1);
and,
column_name BIT;
To specify a bit value literal, use b'val' or 0bval, which is a val that only contains 0 and 1 binary value. The character b starting with
can be written as B. For example, the following two ways are the same:
b01 B11
The above writing methods are all valid bit literals.
However, the leading 0b is case-sensitive, so 0B cannot be used. The following are invalid literal values:
0B'1000'
By default, the character set of place value literals is a binary string, as shown below:
SELECT CHARSET(B''); -- binary
The execution result is as follows -
mysql> SELECT CHARSET(B''); +--------------+ | CHARSET(B'') | +--------------+ | binary | +--------------+ 1 row in set
[Related recommendations: mysql video tutorial]
The above is the detailed content of What type is mysql bit?. For more information, please follow other related articles on the PHP Chinese website!