Complete Cheatsheet

MariaDB & MySQL Data Types

Choosing the right data type saves storage space, increases performance, and prevents data loss. Here is the complete list of all types.

Common These types are the standard for 95% of all use cases. The subtly highlighted types are for special niches.

Numeric Data Types

Tip: Use UNSIGNED for values that never become negative (e.g., IDs) to double the positive value range.

Data Type Size Usage & Properties
TINYINT Common 1 Byte (-128 to 127) For small status flags (e.g., 1=active, 2=locked) or age.
BOOLEAN Common 1 Byte (Alias for TINYINT) Truth values (0 = false, 1 = true). Identical to TINYINT(1) in MySQL.
SMALLINT 2 Bytes For smaller IDs or years (up to ~32,000 or ~65,000 unsigned).
MEDIUMINT 3 Bytes Medium tables (up to ~8 million or 16 million unsigned). Often skipped in favor of INT.
INT Common 4 Bytes (up to ~2 billion) The standard for IDs (with AUTO_INCREMENT) and normal counters.
BIGINT Common 8 Bytes For huge datasets, global transaction IDs, or social media IDs.
DECIMAL Common Fixed-point (Exact) For money and finance! No rounding errors (e.g., DECIMAL(10,2)). For 12.34 use DECIMAL(4,2).
FLOAT Common Floating-point (~7 digits) Scientific calculations or sensor values (inaccuracies possible).
DOUBLE Common Floating-point (~15 digits) Like FLOAT, but more precise. Good for GPS coordinates.
REAL Synonym for DOUBLE Treated as DOUBLE by MySQL by default.
BIT 1 to 64 Bits For bit masks. Rarely used, TINYINT is usually preferred.

Strings & Binary Data

Data Type Property / Max Usage
CHAR Common Fixed length (up to 255) For strings that are always the same length (country codes US, zip codes).
VARCHAR Common Variable length The absolute standard for text (names, emails, titles). Saves space.
TINYTEXT Max 255 Bytes Similar to VARCHAR(255), but stored differently internally.
TEXT Common Max ~65 KB For articles, blog posts, or longer comments and descriptions.
MEDIUMTEXT Max ~16 MB For extremely long texts (e.g., complete HTML pages or books).
LONGTEXT Common Up to 4 GB For huge JSON documents, log files, or Base64 encoded files.
ENUM Common 1 from a list Restrict values (e.g., 'open', 'closed'). Very memory efficient.
SET Multiple from a list Like ENUM, but allows combinations (e.g., 'news','offers').
BINARY / VARBINARY Binary Strings Like CHAR/VARCHAR, but for bytes instead of text (e.g., UUIDs or Hashes).
BLOB Common Max ~65 KB Binary Large Object. For storing small images or files.
MEDIUMBLOB / LONGBLOB Up to 4 GB For large files (videos, large archives) directly in the database.

Date and Time

Data Type Format Usage
DATE Common YYYY-MM-DD For birthdays, start dates of contracts, or holidays (without time).
DATETIME Common YYYY-MM-DD HH:MM:SS For fixed appointments. Remains exactly as saved (ignores time zones).
TIMESTAMP Common YYYY-MM-DD HH:MM:SS Perfect for created_at / updated_at. Converts to UTC for storage.
TIME Common HH:MM:SS For times of day (opening hours) or to store a duration (e.g., race times).
YEAR YYYY When only the year is relevant (e.g., year of manufacture).

Special Types & Spatial Data

Data Type Category Usage
JSON Common Document Store Valid JSON format. Allows direct queries in JSON objects and arrays.
GEOMETRY Spatial (Base) Can store any geometric value (polygons, points, etc.).
POINT Spatial (Point) Stores an exact X/Y coordinate (e.g., the exact location on a map).
LINESTRING, POLYGON Spatial (Shapes) A curve/line or a closed area (e.g., a street or a lake).

Extra: What do the numbers in brackets mean?

You often see data types with round brackets, like VARCHAR(255) or INT(11). The meaning differs drastically depending on the data type!

VARCHAR(255)

Maximum Length

The number represents the maximum number of characters. 255 means the text can be at most 255 characters long.

Warning!

INT(11)

Display Width

A common misconception: The 11 does not limit the value! An INT always stores up to ~2.1 billion. The 11 only defines the padding for clients (with ZEROFILL).

DECIMAL(10,2)

Precision & Scale

The first number (10) is the total number of digits. The second (2) is the number of decimal places. For 12.34 it's DECIMAL(4,2).