MySQL Data Types: INT, DECIMAL, VARCHAR, DATE, ENUM and More

MySQL 60 min min read Updated: Nov 27, 2026 Beginner
MySQL Data Types: INT, DECIMAL, VARCHAR, DATE, ENUM and More
Beginner Topic 2 of 3

Why Types Matter

A column type decides what values are allowed, how much space they use, and how they sort and compare. The right type keeps data correct and queries fast.

Integer Types

TypeBytesSigned rangeUse for
TINYINT1-128 to 127Flags, small codes, ratings
SMALLINT2-32,768 to 32,767Small counts, years
INT4about -2.1 billion to 2.1 billionNormal ids and counts
BIGINT8about 9.2 quintillionHuge tables, large counters

Add UNSIGNED to allow only zero and positive numbers, which doubles the positive range (an INT UNSIGNED goes up to about 4.29 billion). Ids and quantities are good candidates.

sql CREATE TABLE ratings (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, stars TINYINT UNSIGNED NOT NULL); INSERT INTO ratings (stars) VALUES (5), (4); SELECT id, stars FROM ratings ORDER BY id;

Result:

idstars
15
24

A value outside the range is rejected in strict mode:

sql CREATE TABLE ratings (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, stars TINYINT UNSIGNED NOT NULL); INSERT INTO ratings (stars) VALUES (300);
Error

ERROR 1264: Out of range value for column 'stars' at row 1

INT(11) is not a size In INT(11) the number is only a display hint that MySQL 8 has deprecated. It does not change the range. Write INT.

DECIMAL, FLOAT and DOUBLE

Use **DECIMAL(p, s)** for money: p total digits, s digits after the decimal point. It is exact. FLOAT and DOUBLE are approximate binary numbers, good for science and measurements but not for money.

sql SELECT CAST(0.1 AS DECIMAL(5,2)) + CAST(0.2 AS DECIMAL(5,2)) AS decimal_sum, 0.1E0 + 0.2E0 AS double_sum, ROUND(0.1E0 + 0.2E0, 2) AS double_rounded;

Result:

decimal_sumdouble_sumdouble_rounded
0.300.30.3

DECIMAL gives exactly 0.30. The double is stored as a binary approximation; MySQL prints a short form, but comparisons can still surprise you:

sql SELECT (0.1E0 + 0.2E0 = 0.3E0) AS double_equal, (0.1 + 0.2 = 0.3) AS decimal_equal;

Result:

double_equaldecimal_equal
01

double_equal is 0 (false) while decimal_equal is 1 (true). Never compare floating point numbers with =.

Text Types

TypeMax sizeNotes
CHAR(n)255 charactersFixed length, padded. For codes like 'IN'
VARCHAR(n)up to 65,535 bytes per rowVariable length. The normal choice for names and emails
TEXT65,535 bytesLong text. Cannot have a plain default value
MEDIUMTEXT, LONGTEXT16 MB, 4 GBArticles, documents

With utf8mb4, each character may take up to 4 bytes, so VARCHAR(255) can use up to 1020 bytes.

sql CREATE TABLE codes (country CHAR(2) NOT NULL, name VARCHAR(30) NOT NULL); INSERT INTO codes VALUES ('IN', 'India'), ('US', 'United States'); SELECT country, name, CHAR_LENGTH(name) AS characters, LENGTH(name) AS bytes FROM codes ORDER BY country;

Result:

countrynamecharactersbytes
INIndia55
USUnited States1313
sql CREATE TABLE codes (country CHAR(2) NOT NULL, name VARCHAR(5) NOT NULL); INSERT INTO codes VALUES ('IN', 'Hindustan');
Error

ERROR 1406: Data too long for column 'name' at row 1

Strict mode rejects text that is too long instead of cutting it.

Date and Time Types

TypeStoresRangeNotes
DATEYear-month-day1000-01-01 to 9999-12-31Birthdays, order dates
TIMETime or duration-838:59:59 to 838:59:59Durations
DATETIMEDate and time1000 to 9999Stored as written, no time zone conversion
TIMESTAMPDate and time1970 to 2038Stored as UTC and converted to the session time zone
YEARYear1901 to 2155Rarely used
sql CREATE TABLE events (id INT PRIMARY KEY, happened DATETIME NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP); INSERT INTO events (id, happened) VALUES (1, '2025-03-15 14:30:00'); SELECT id, happened, created IS NOT NULL AS has_created FROM events;

Result:

idhappenedhas_created
12025-03-15 14:30:001
DATETIME or TIMESTAMP? TIMESTAMP stops at the year 2038 and changes with the session time zone, so many teams prefer DATETIME and store UTC in the application. Choose one convention and keep it.

ENUM and SET

ENUM stores one value from a fixed list, using 1 or 2 bytes internally.

sql CREATE TABLE tickets (id INT PRIMARY KEY, status ENUM('open', 'closed', 'waiting') NOT NULL DEFAULT 'open'); INSERT INTO tickets (id) VALUES (1); INSERT INTO tickets VALUES (2, 'closed'); SELECT id, status FROM tickets ORDER BY id;

Result:

idstatus
1open
2closed
sql CREATE TABLE tickets (id INT PRIMARY KEY, status ENUM('open', 'closed', 'waiting') NOT NULL DEFAULT 'open'); INSERT INTO tickets VALUES (3, 'done');
Error

ERROR 1265: Data truncated for column 'status' at row 1

ENUM trade-off Adding a new value later needs ALTER TABLE, and sorting follows the list order, not the alphabet. Many designers prefer a small lookup table plus a foreign key for values that change.

BOOLEAN

BOOLEAN is just a synonym for TINYINT(1). TRUE is 1 and FALSE is 0.

sql CREATE TABLE flags (id INT PRIMARY KEY, active BOOLEAN NOT NULL DEFAULT TRUE); INSERT INTO flags (id) VALUES (1); INSERT INTO flags VALUES (2, FALSE); SELECT id, active FROM flags ORDER BY id;

Result:

idactive
11
20

JSON and BLOB (Preview)

JSON stores structured documents with validation and special functions (a later lesson covers it). BLOB stores binary data. For large files such as photos, store the file in object storage and keep only its path in the database.

Choosing Types: A Quick Guide

DataGood type
Primary key, countINT UNSIGNED or BIGINT UNSIGNED
Price, moneyDECIMAL(10,2)
Name, email, titleVARCHAR(100) and similar
Country or currency codeCHAR(2), CHAR(3)
Long descriptionTEXT
Date onlyDATE
Moment in timeDATETIME (store UTC) or TIMESTAMP
Status with few fixed valuesENUM, or a lookup table
Yes/no flagBOOLEAN
Phone numberVARCHAR(20), never a number

Phone numbers, postal codes and ids from other systems are text: they can start with 0 and you never add them up.

Common Beginner Mistakes

MistakeWhat happensFix
Using FLOAT for moneyRounding errorsUse DECIMAL
Storing dates as textWrong sorting, no date functionsUse DATE or DATETIME
VARCHAR(255) everywhereWaste and sloppy designPick a sensible limit
Phone number as INTLeading zeros and + lostVARCHAR
Ignoring UNSIGNED on idsHalf the key range unusedUse UNSIGNED for ids and counts

Practice

  1. Create a products table with the right types for id, name, price, stock, created and active.
  2. Insert a price with 3 decimals into a DECIMAL(10,2) column and see what is stored.
  3. Create an ENUM column and try an invalid value.
  4. Compare CHAR_LENGTH and LENGTH for the text 'café'.

Conclusion

Pick the smallest sensible type: INT UNSIGNED for ids, DECIMAL for money, VARCHAR for text, DATE or DATETIME for time, ENUM or lookup tables for fixed lists, and keep phone numbers as text.

Quick Summary: INT, DECIMAL vs FLOAT, CHAR, VARCHAR, TEXT, DATE, DATETIME, TIMESTAMP, ENUM, BOOLEAN.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators