MySQL Data Types

MySQL Data Types – Complete Guide with Examples
In MySQL, data types define what kind of data a column can store. Choosing the correct data type is critical for performance, storage efficiency, and data accuracy.
MySQL data types are broadly divided into:
- Numeric Data Types
- String (Character) Data Types
- Date & Time Data Types
- Boolean Data Type
- Binary & Special Data Types
Why Data Types Are Important in MySQL?
- Reduce storage usage
- Improve query performance
- Prevent invalid data
- Ensure accurate calculations
- Essential for interviews & production databases
1. Numeric Data Types
Used to store numbers.
Integer Data Types
| Data Type | Size | Range |
|---|---|---|
TINYINT | 1 byte | -128 to 127 |
SMALLINT | 2 bytes | -32,768 to 32,767 |
MEDIUMINT | 3 bytes | -8M to 8M |
INT | 4 bytes | -2B to 2B |
BIGINT | 8 bytes | Very large |
Example
Decimal & Floating Types
| Data Type | Description |
|---|---|
FLOAT | Approximate decimal |
DOUBLE | Higher precision |
DECIMAL(p,s) | Exact decimal (recommended for money) |
Example
- Use
DECIMALfor financial data.
2. String (Character) Data Types
Used to store text.
Character Types
| Data Type | Description |
|---|---|
CHAR(n) | Fixed-length string |
VARCHAR(n) | Variable-length string |
Example
- Most commonly used
- Efficient storage
Text Types
| Data Type | Max Size |
|---|---|
TINYTEXT | 255 bytes |
TEXT | 65 KB |
MEDIUMTEXT | 16 MB |
LONGTEXT | 4 GB |
Example
- Used for long content
3. Date & Time Data Types
Used to store date and time values.
| Data Type | Format |
|---|---|
DATE | YYYY-MM-DD |
TIME | HH:MM:SS |
DATETIME | YYYY-MM-DD HH:MM:SS |
TIMESTAMP | Auto-updated date & time |
YEAR | YYYY |
Example
TIMESTAMPauto-updates on row modification.
4. Boolean Data Type
MySQL does not have a real BOOLEAN type.
BOOLEAN=TINYINT(1)0→ false1→ true
Example
5. Binary Data Types
Used to store binary data (images, files).
| Data Type | Description |
|---|---|
BINARY | Fixed-length binary |
VARBINARY | Variable-length |
BLOB | Binary large object |
Example
6. ENUM & SET Data Types
ENUM
Stores one value from a predefined list.
- Saves space
- Limited choices
SET
Stores multiple values from a list.
Choosing the Right Data Type (Quick Guide)
| Data | Best Type |
|---|---|
| ID | INT / BIGINT |
| Name | VARCHAR |
| Price | DECIMAL |
| Description | TEXT |
| Date | DATE |
| Date + Time | DATETIME |
| Status | BOOLEAN |
| File | BLOB |
Common Mistakes
- Using
VARCHARfor numbers - Using
FLOATfor money - Overusing
TEXT Wrong date type selection- Not setting size limits
Best Practices
- Choose smallest suitable data type
- Use
VARCHARinstead ofCHAR UseDECIMALfor currency- Use
TIMESTAMPfor audit fields - Avoid unnecessary large fields
Interview Questions: MySQL Data Types
1. Difference between CHAR and VARCHAR?
CHAR is fixed-length, VARCHAR is variable-length.
2. Best data type for money?
DECIMAL
3. Does MySQL support BOOLEAN?
Internally uses TINYINT(1).
4. Difference between DATETIME and TIMESTAMP?
TIMESTAMP auto-updates and is timezone-aware.
5. What data type for long text?
TEXT / LONGTEXT
Summary
- MySQL data types control storage and performance
- Numeric, string, date types are core
- Correct data types prevent bugs
- Critical for backend & interviews
- Foundation of database design
Mastering MySQL Data Types will make your SQL schemas efficient, scalable, and professional
