← Back to MySQL Course | Chapter 1: Introduction & Basics | Lesson 7 of 8

MySQL Data Types Overview

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

sql
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

sql
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

sql
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

sql
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

sql
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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.