Appearance
MySQL / MariaDB Data Types
Most commonly used data types in MySQL and MariaDB
Numeric Data Types
Integer Types
Used for whole numbers.
| Type | Size | Range (Signed) | Typical Use |
|---|---|---|---|
TINYINT | 1 byte | -128 to 127 | Flags, booleans (0/1) |
SMALLINT | 2 bytes | -32,768 to 32,767 | Small counters |
MEDIUMINT | 3 bytes | -8,388,608 to 8,388,607 | Rarely used |
INT | 4 bytes | -2,147,483,648 to 2,147,483,647 | Default integer |
BIGINT | 8 bytes | Very large | IDs, large counters |
TIP
UNSIGNEDdoubles the positive range.INTis the most common choice.BIGINTis typical for primary keys in large systems.
Floating Point Types
Used for approximate numeric values.
| Type | Description | Typical Use |
|---|---|---|
FLOAT | 32-bit | Scientific data |
DOUBLE | 64-bit | Calculations needing more precision |
TIP
- Not exact. Avoid for money.
Fixed-Point (Exact) Types
Used when precision matters.
| Type | Description | Typical Use |
|---|---|---|
DECIMAL(p,s) | Exact number with precision | Money, financial data |
Example:
sql
DECIMAL(10,2)String (Text) Data Types
Character Types
| Type | Description | Typical Use |
|---|---|---|
CHAR(n) | Fixed-length string | Codes, ISO values |
VARCHAR(n) | Variable-length string | Names, emails |
Text Types
| Type | Max Size |
|---|---|
TINYTEXT | 255 bytes |
TEXT | 64 KB |
MEDIUMTEXT | 16 MB |
LONGTEXT | 4 GB |
Date and Time Data Types
| Type | Description | Typical Use |
|---|---|---|
DATE | Date only | Birthdays |
TIME | Time only | Durations |
DATETIME | Date and time | Events |
TIMESTAMP | Unix-based datetime | Audit fields |
YEAR | Year | Rare |
Boolean
| Type | Description |
|---|---|
BOOLEAN / BOOL | Alias for TINYINT(1) |
Binary Data Types
| Type | Description |
|---|---|
BINARY(n) | Fixed-length binary |
VARBINARY(n) | Variable-length binary |
BLOB | Binary large object |
ENUM and SET
ENUM
sql
ENUM('draft', 'published', 'archived')SET
sql
SET('read', 'write', 'execute')JSON
| Type | Description |
|---|---|
JSON | Structured JSON data |
Most Common Choices
| Purpose | Recommended Type |
|---|---|
| Primary key | BIGINT / INT UNSIGNED |
| Text fields | VARCHAR |
| Long text | TEXT |
| Money | DECIMAL |
| Boolean | TINYINT(1) |
| Timestamps | DATETIME / TIMESTAMP |
| JSON data | JSON |