MySQL Tutorials - Herong's Tutorial Examples - v4.46, by Herong Yang
Table Column Types for Bit Strings
Describes 2 types of table columns to store bit strings: BIT and BIT VARYING.
There are 2 types of table columns to store bit strings: BIT and BIT VARYING.
"BIT(length)" - Bit string with fixed length counted in bits.
"BIT VARYING(length)" - Bit string with varying length counted in bits. BIT VARYING is not supported by MySQL yet.
Examples of B string column types, BitStringColumns.sql:
-- BitStringColumns.sql -- Copyright (c) 1999 HerongYang.com. All Rights Reserved. -- CREATE TABLE BitString ( Line VARCHAR(2), A BIT(32), B CHAR(4) -- C BIT VARYING(8) -- not supported by MySQL ); INSERT INTO BitString VALUES ( '1', 'AAA', 'AAA' ); INSERT INTO BitString VALUES ( '2', X'424242', X'424242' ); INSERT INTO BitString VALUES ( '3', BINARY(X'434343'), BINARY(X'434343') ); SELECT * FROM BitString; DROP TABLE BitString;
Running BitStringColumns.sql on MySQL 8.0, 5.7, 5.6, and 5.0 servers, gives you correct output:
herong> %mysql%\bin\mysql --user=root --password=TopSecret test \ < BitStringColumns.sql Line A B 1 \0AAA AAA 2 \0BBB BBB 3 \0CCC CCC
But running BitStringColumns.sql on MySQL 4.0 server gives you incorrect output:
Line A B 1 0 AAA 2 127 BBB 3 0 CCC
Table of Contents
MySQL Introduction and Installation
Introduction of MySQL Programs
Perl Programs and MySQL Servers
Java Programs and MySQL Servers
Character Strings and Bit Strings
►Table Column Types for Different Types of Values
Table Column Types for Character Strings
Table Column Types for Byte Strings
►Table Column Types for Bit Strings
Table Column Types for Exact Numbers
Table Column Types for Approximate Numbers
Table Column Types for Date and Time Values
Table Column Types for LOB (Large OBject)
Table Column Types for Look Up Values
Table Column Types for JSON Documents
Table Column Types for Spatial Geometry Data
Using DDL to Create Tables and Indexes
Using DML to Insert, Update and Delete Records
Using SELECT to Query Database
Window Functions for Statistical Analysis
Use Index for Better Performance
Transaction Management and Isolation Levels
Defining and Calling Stored Procedures
Variables, Loops and Cursors Used in Stored Procedures
System, User-Defined and Stored Procedure Variables
Storage Engines in MySQL Server
InnoDB Storage Engine - Primary and Secondary Indexes
Performance Tuning and Optimization
Installing MySQL Server on Linux