Time to cover MySQL data types. What each column can store, and how to pick the right one.
Why data types matter
Every column in a MySQL table has a data type. It controls what values the column accepts and how much storage it uses. Picking the right type keeps your database efficient and your data accurate.
Numeric data types
Common numeric types:
- INT: whole numbers. Good for IDs and counts. Example:
id INT. - DECIMAL(M, N): exact decimal values. M is total digits, N is digits after the decimal point. Example:
price DECIMAL(5, 2)stores values up to 999.99. - FLOAT and DOUBLE: floating-point numbers.
DOUBLEis more precise thanFLOAT. Use for scientific values where exact precision matters less.
String data types
For text:
- VARCHAR(L): variable-length string. L is the maximum length. Example:
name VARCHAR(100). - TEXT: longer text – descriptions, comments. Up to 65,535 characters.
- CHAR(L): fixed-length string. Pads with spaces if the value is shorter. Faster for lookups, but wastes space on short values.
Date and time data types
- DATE: a date in YYYY-MM-DD format. Example:
birth_date DATE. - TIME: time in HH:MM:SS format.
- DATETIME: date and time together (YYYY-MM-DD HH:MM:SS). Example:
created_at DATETIME. - TIMESTAMP: similar to DATETIME, but often used to auto-record when a row changes.
Specialised data types
- ENUM: a string that must be one of a fixed list. Example:
status ENUM('active', 'inactive', 'pending'). - BLOB: binary data – images, files, that sort of thing.
Practical example
A products table for an online shop:
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10, 2),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
Breaking that down:
id: auto-incrementing integer, primary key.name: variable-length string, up to 255 characters, required.description: TEXT for longer product copy.price: DECIMAL for exact money values.created_at: DATETIME, defaults to the current timestamp on insert.
Best practices for data types
- Match the data: pick types that fit what you actually store.
- Watch storage: larger types use more space. Do not over-specify.
- Plan ahead: think about how your data might grow before you lock in column sizes.
There is no single right answer for every column, but the more tables you design, the quicker the choices become.

