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

MySQL Data Types Overview

Data types are like different kinds of containers: some are for whole numbers, some for exact money amounts, some for words and some for dates. Choosing the right one keeps things tidy.
Syntax
sql
column_name datatype[(size)]

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"}');
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Using FLOAT or DOUBLE for money, which stores approximate values, when DECIMAL(10,2) keeps exact cents.
  2. Choosing VARCHAR(255) for everything, or a CHAR for values of varying length, wasting space or padding values.
  3. Expecting BOOLEAN to be a special type, when MySQL stores it as TINYINT(1).
🔒

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.