This cheatsheet covers the most commonly used MySQL data types, their descriptions, and usage examples.
- Numeric Data Types
- Integer Types
- Decimal Types
- String Data Types
- Date and Time Data Types
- Binary Data Types
- JSON Data Type
- Spatial Data Types
Numeric Data Types
Integer Types
-- TINYINT: -128 to 127 or 0 to 255 (unsigned)
column_name TINYINT;
-- SMALLINT: -32768 to 32767 or 0 to 65535 (unsigned)
column_name SMALLINT;
-- MEDIUMINT: -8388608 to 8388607 or 0 to 16777215 (unsigned)
column_name MEDIUMINT;
-- INT: -2147483648 to 2147483647 or 0 to 4294967295 (unsigned)
column_name INT;
-- BIGINT: -9223372036854775808 to 9223372036854775807 or 0 to 18446744073709551615 (unsigned)
column_name BIGINT;
Decimal Types
-- DECIMAL: Fixed-point number (M, D) where M is the total digits and D is the decimal places
column_name DECIMAL(10, 2); -- Up to 10 digits with 2 decimal places
-- FLOAT: Single-precision floating-point number
column_name FLOAT;
-- DOUBLE: Double-precision floating-point number
column_name DOUBLE;
String Data Types
-- CHAR: Fixed-length string (0-255 characters)
column_name CHAR(50);
-- VARCHAR: Variable-length string (0-65,535 characters)
column_name VARCHAR(255);
-- TEXT: Variable-length string (up to 65,535 characters)
column_name TEXT;
-- MEDIUMTEXT: Variable-length string (up to 16,777,215 characters)
column_name MEDIUMTEXT;
-- LONGTEXT: Variable-length string (up to 4,294,967,295 characters)
column_name LONGTEXT;
-- ENUM: String object with a value chosen from a list of permitted values
column_name ENUM('value1', 'value2', 'value3');
-- SET: String object that can have 0 or more values from a list of permitted values
column_name SET('value1', 'value2', 'value3');
Date and Time Data Types
-- DATE: Date in YYYY-MM-DD format
column_name DATE;
-- TIME: Time in HH:MM:SS format
column_name TIME;
-- DATETIME: Date and time combination in YYYY-MM-DD HH:MM:SS format
column_name DATETIME;
-- TIMESTAMP: Timestamp in YYYY-MM-DD HH:MM:SS format, used for tracking changes
column_name TIMESTAMP;
-- YEAR: Year in 2-digit or 4-digit format
column_name YEAR;
Binary Data Types
-- BINARY: Fixed-length binary string
column_name BINARY(50);
-- VARBINARY: Variable-length binary string
column_name VARBINARY(255);
-- BLOB: Binary Large Object, variable-length (up to 65,535 bytes)
column_name BLOB;
-- MEDIUMBLOB: Medium-sized BLOB (up to 16,777,215 bytes)
column_name MEDIUMBLOB;
-- LONGBLOB: Large BLOB (up to 4,294,967,295 bytes)
column_name LONGBLOB;
JSON Data Type
-- JSON: Stores JSON-format data
column_name JSON;
Spatial Data Types
-- GEOMETRY: Stores geometry values of any type
column_name GEOMETRY;
-- POINT: Stores X and Y coordinates
column_name POINT;
-- LINESTRING: Stores a series of points
column_name LINESTRING;
-- POLYGON: Stores a polygon
column_name POLYGON;