Summary: in this tutorial, you will learn about MariaDB data types and how to use them effectively for designing a table.
Before designing a database in MariaDB, you should consider the available data types so that you can select the most optimal ones for storing data. MariaDB provides you with many data types including:
- Numeric data types
- String data types
- Temporal data types
- Spatial data types
Each data type has the following properties:
- The value that it can present.
- The storage size
- The values can be indexed or not.
- How values can be compared.
MariaDB numeric data types
MariaDB supports many kinds of numeric types including the exact and approximate numeric data types. The following table shows the summary of numeric types supported by MariaDB:
Numeric Types | Description |
---|---|
TINYINT | A very small integer |
SMALLINT | A small integer |
MEDIUMINT | A medium-sized integer |
INT | A standard integer |
BIGINT | A large integer |
DECIMAL | A fixed-point number |
FLOAT | A single-precision floating-point number |
DOUBLE | A double-precision floating-point number |
BIT | A bit |
MariaDB Boolean data type
MariaDB uses the TINYINT(1)
to represent Boolean values. In MariaDB, zero (0) means false and non-zero means true. The BOOLEAN
and BOOL
are the synonym of TINYINT(1)
.
MariaDB string data types
MariaDB string types can hold any string data including plain text, binary data, and even contents of files. The following table displays string data types in MariaDB:
String Types | Description |
---|---|
CHAR | A fixed-length nonbinary (character) string |
VARCHAR | A variable-length non-binary string |
BINARY | A fixed-length binary string |
VARBINARY | A variable-length binary string |
TINYBLOB | A very small BLOB (binary large object) |
BLOB | A small BLOB |
MEDIUMBLOB | A medium-sized BLOB |
LONGBLOB | A large BLOB |
TINYTEXT | A very small non-binary string |
TEXT | A small non-binary string |
MEDIUMTEXT | A medium-sized non-binary string |
LONGTEXT | A large non-binary string |
ENUM | An enumeration |
SET | A set |
MariaDB temporal types
MySQL temporal types including types that represent a date without time, a time without date, a datetime, a timestamp, and year. This table shows the MariaDB temporal data types:
Temporal Data Types | Description |
---|---|
DATE | A date value in CCYY-MM-DD format |
TIME | A time value in hh:mm:ss format |
DATETIME | A date and time value inCCYY-MM-DD hh:mm:ss format |
TIMESTAMP | A timestamp value in CCYY-MM-DD hh:mm:ss format |
YEAR | A year value in CCYY or YY format |
MariaDB spatial data types
MariaDB supports many spatial data types that contain various kinds of geographical values
Spatial Data Types | Description |
---|---|
GEOMETRY | A spatial value of any type |
POINT | A point (a pair of X-Y coordinates) |
LINESTRING | A curve (one or more POINT values) |
POLYGON | A polygon |
GEOMETRYCOLLECTION | A collection of GEOMETRY values |
MULTILINESTRING | A collection of LINESTRING values |
MULTIPOINT | A collection of POINT values |
MULTIPOLYGON | A collection of POLYGON values |
In this tutorial, you have learned various MariaDB data types including numeric, string, spatial data types,