HomeMYSQLWhat are the different data types in MySQL?

What are the different data types in MySQL?

In MySQL, data types define the kind of values that can be stored in a column. They are broadly categorized into three main groups: Numeric, Date & Time, and String (Character) types. Here’s a detailed breakdown:


1. Numeric Data Types

Used to store numbers. They are divided into integer types and floating-point/decimal types.

a) Integer types (whole numbers):

TypeStorageRange (Signed)
TINYINT1 byte-128 to 127
SMALLINT2 bytes-32,768 to 32,767
MEDIUMINT3 bytes-8,388,608 to 8,388,607
INT / INTEGER4 bytes-2,147,483,648 to 2,147,483,647
BIGINT8 bytes-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

b) Floating-point types (decimal numbers):

TypeDescription
FLOATSingle-precision floating-point
DOUBLE / REALDouble-precision floating-point
DECIMAL / NUMERICExact fixed-point numbers (used for money)

2. Date & Time Data Types

Used to store dates, times, or both.

TypeFormat / Example
DATEYYYY-MM-DD (e.g., 2025-08-16)
DATETIMEYYYY-MM-DD HH:MM:SS
TIMESTAMPYYYY-MM-DD HH:MM:SS (auto-updates on row change)
TIMEHH:MM:SS
YEARYYYY (e.g., 2025)

3. String (Character) Data Types

Used to store text or binary data.

a) Character types:

TypeDescription
CHAR(n)Fixed-length string, up to 255 characters
VARCHAR(n)Variable-length string, up to 65535 characters depending on row size

b) Text types (large strings):

TypeMax Size
TINYTEXT255 bytes
TEXT65,535 bytes (64 KB)
MEDIUMTEXT16,777,215 bytes (16 MB)
LONGTEXT4,294,967,295 bytes (4 GB)

c) Binary types:

TypeDescription
BINARY(n)Fixed-length binary data
VARBINARY(n)Variable-length binary data
BLOBBinary Large Object (TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB)

4. Other Special Types

  • ENUM: A string object that can have only one value from a defined list. Example: ENUM('small', 'medium', 'large').
  • SET: A string object that can have zero or more values from a defined list. Example: SET('a','b','c').

💡 Tips:

  • Use INT for numbers without decimals.
  • Use DECIMAL for precise financial calculations.
  • Use VARCHAR for variable-length text to save storage.
  • Use DATETIME or TIMESTAMP for date-time values depending on whether you want auto-updates.

Share: 

No comments yet! You be the first to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *