devnotes.

MySQL Data Types

Choosing the right data type keeps your database small, fast and correct.

Numeric

TypeStorageSigned range
TINYINT1 byte−128 to 127
SMALLINT2 bytes−32,768 to 32,767
MEDIUMINT3 bytes±8.3 million
INT4 bytes±2.14 billion
BIGINT8 bytes±9.2 quintillion
DECIMAL(p,s)variesExact, for money
FLOAT / DOUBLE4 / 8 bytesApproximate

Add UNSIGNED to double the positive range: INT UNSIGNED goes up to 4.29 billion. Use BOOLEAN (an alias for TINYINT(1)) for true/false.

Never store money in FLOAT. 0.1 + 0.2 is not 0.3 in binary floating point. Use DECIMAL(10,2).

String

TypeNotes
CHAR(n)Fixed length, padded; fast for codes like BD, MD5
VARCHAR(n)Variable length up to 65,535 bytes per row
TEXT familyTINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT (up to 4 GB)
BINARY/VARBINARYRaw bytes
BLOB familyBinary large objects (files, images)
ENUM('a','b')One value from a fixed list
SET('a','b')Zero or more values from a list

Date and time

TypeFormatRange
DATEYYYY-MM-DD1000–9999
TIMEHH:MM:SS−838:59:59 to 838:59:59
DATETIMEYYYY-MM-DD HH:MM:SS1000–9999, no timezone conversion
TIMESTAMPsame1970–2038, converted to/from UTC
YEARYYYY1901–2155

JSON

MySQL 5.7+ has a native JSON type with validation and indexable generated columns.

CREATE TABLE settings (
  user_id INT PRIMARY KEY,
  prefs   JSON
);
INSERT INTO settings VALUES (1, '{"theme":"dark","lang":"bn"}');
SELECT prefs->>'$.theme' AS theme FROM settings;

Practical rules

  • Pick the smallest type that fits — smaller rows mean more rows per page and faster scans.
  • Use VARCHAR(255) for emails/names, not TEXT — TEXT cannot be fully indexed.
  • Store timestamps in UTC and format in the application layer.
  • Use utf8mb4 charset so emojis and full Bengali text work correctly.
MySQL Data Types — Numeric, String, Date and JSON | DevNotes