MySQL Data Types Overview
In this page:
Numeric Data Types
Numeric types like INT store whole numbers efficiently, while DECIMAL stores exact fixed-point values — critical for money, where floating-point rounding errors would silently corrupt totals over many transactions.
Example: Numeric Data Types
CREATE TABLE prices (id INT, quantity INT, amount DECIMAL(10,2));
String Data Types
CHAR reserves a fixed number of bytes regardless of the actual string length (padding short values with spaces), while VARCHAR only stores what's needed plus a small length prefix, making it the better default for most text.
Example: String Data Types
CREATE TABLE users (code CHAR(5), username VARCHAR(50));
Date and Time Types
DATE stores just a calendar day with no time component, whereas DATETIME stores both the day and the exact time down to the second (or microsecond), so pick DATE only when time-of-day genuinely doesn't matter.
Example: Date and Time Types
CREATE TABLE events (event_date DATE, created_at DATETIME);
Boolean Data Type
MySQL has no dedicated boolean column type; it silently maps TRUE/FALSE onto TINYINT(1), where 0 means false and any nonzero value is treated as true — worth knowing before you're surprised by a value like 2 evaluating as true.
Example: Boolean Data Type
CREATE TABLE flags (is_active TINYINT(1));
INSERT INTO flags VALUES (1);
JSON Data Type
The native JSON type stores semi-structured documents inside a normal column and validates the syntax on insert, letting you mix relational and document-style data without a separate NoSQL database.
Example: JSON Data Type
CREATE TABLE settings (config JSON);
INSERT INTO settings VALUES ('{"theme": "dark"}');
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: