Data Types in MySQL

Every MySQL column has a data type. The type determines what values the column can store, how MySQL interprets them, and how much storage or precision is available.

CREATE TABLE product (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    name VARCHAR(100) NOT NULL,
    price DECIMAL(10,2) NOT NULL,
    created_at DATETIME NOT NULL,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
On this page — Show page sectionsHide page sections

Main MySQL data-type groups

GroupExamplesTypical use
NumericINT, BIGINT, DECIMAL, FLOAT, DOUBLECounts, IDs, prices, measurements
Date & timeDATE, TIME, DATETIME, TIMESTAMP, YEARDates, timestamps, durations
Character/textCHAR, VARCHAR, TEXTNames, descriptions, text
BinaryBINARY, VARBINARY, BLOBRaw bytes and binary objects

Boolean values in MySQL: MySQL uses TINYINT(1) for BOOLEAN and BOOL. Learn how TRUE, FALSE, NULL and Boolean comparisons work in our MySQL BOOLEAN and TINYINT(1) tutorial .

Choose the narrowest type that correctly represents the values you need. For exact money-like values, prefer DECIMAL rather than approximate floating-point types.

Choosing data types for a real table

The sample product table above combines INT for a generated identifier, VARCHAR for names, DECIMAL(10,2) for exact prices and DATETIME for an entered timestamp. The choice of data type changes which values MySQL accepts and how they are handled.

After creating the sample table, insert a row and read it back:

INSERT INTO product (name, price, created_at)
VALUES ('Notebook', 149.50, '2026-11-14 10:30:00');

SELECT name, price, DATE(created_at) AS added_on
FROM product
ORDER BY id;

Result after inserting one row into a new empty product table

namepriceadded_on
Notebook149.502026-11-14

Which MySQL type should I select?

NeedTypical typeImportant detail
Whole-number countsINTCheck its signed/unsigned range
Money or exact decimalsDECIMAL(M,D)Set precision and scale to suit the data
Names and labelsVARCHAR(n)Use a suitable character set such as utf8mb4
Long textTEXTDifferent from a binary BLOB
Date onlyDATENo time-of-day component
Local wall-clock date and timeDATETIMENot automatically converted by session time zone
Raw bytesBLOBUse only when the binary content belongs in the database

Inspect the columns after CREATE TABLE

DESCRIBE product;

This shows column names, their MySQL types, NULL rules and key/default information. Use SHOW TABLES to see whether the table exists, and CREATE TABLE to define a new one.

Common mistakes

Do not assume that integer display width limits the allowed number of digits. Avoid FLOAT for exact financial totals; and remember that VARCHAR, TEXT and BLOB serve different needs. See the dedicated numeric, date/time and binary pages.

Back to top ↑




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer