This post provides a list of all the data types available in MySQL with the limitations where applicable.
The data types supported by MySQL include Numeric, Date and Time, String, Spatial Data, and JSON.
The numeric data types include Integer, Fixed-Point, Floating-Point, and Bit-Value. This section provides a list of all the numeric data types with their range.
Integer Types(Exact Value)
The standard SQL integer types available in MySQL include INT and SMALLINT. Additional integer types supported by MySQL include TINYINT, MEDIUMINT, and BIGINT.
While creating the Table or Column, we can optionally specify the maximum display width within the parenthesis. The display width has no impact on the minimum and maximum values.
Notes: Defining the display width within the parenthesis is deprecated for integer types since MySQL 8.0.17 and it will be removed in future releases. Ex: INT(10). One must not specify the display width for all the new tables and columns.
The below-mentioned table provides the list of all the integer types with size, minimum value, and maximum value.
|Type||Size||Min Signed||Max Signed||Min Unsigned||Max Unsigned|
|BIGINT||8 Bytes||-263||263 - 1||0||264 - 1|
Fixed-Point Types(Exact Value)
Standard SQL types available in MySQL include DECIMAL and NUMERIC. These data types store the exact numeric value preserving the exact precision.
NUMERIC is implemented as DECIMAL, hence both follow the same rules as mentioned below.
DECIMAL - Maximum number of digits is 65 including precision(M), and scale(D) and the maximum number of supported decimals or scale(D) is 30.
The DECIMAL type can be declared as listed below.
DECIMAL(M, D) - With precision and scale - M is to specify precision and D is for scale.
DECIMAL(M) - Without scale - DECIMAL(M) or DECIMAL(M, 0).
DECIMAL - Without precision and scale - The precision(M) will be 10 by default.
Floating-Point Types(Approximate Value)
Standard SQL types available in MySQL include FLOAT or FLOAT(p) where p is precision.
MySQL also supports nonstandard FLOAT(M, D). It's deprecated since MySQL 8.0.17 and it will be removed in future releases.
FLOAT and DOUBLE data types represent approximate numeric data values. MySQL supports 4 bytes for single-precision FLOAT values and 8 bytes for double-precision DOUBLE values.
FLOAT(p) - MySQL uses the optional precision value to only determine the actual storage size. The precision value from 0 to 23 results in 4-byte single-precision FLOAT column, and value from 24 to 53 results in 8-byte double-precision DOUBLE column.
The BIT data type is being used to store binary values. For example - values b'111' and b'10000000' represent 7 and 128, respectively.
BIT(M) - Stores M-bit values where M can range from 1 to 64.
Date and Time Types
The date and time data types include DATE, DATETIME, TIMESTAMP, TIME, and YEAR types. MySQL supports either 2 digits (relaxed format for string values) or 4 digits values for the Year part. I have used the 4 digits Year format in this section which is also the standard format.
DATE - The DATE type follows the standard format YYYY-MM-DD and used for date values without time part.
DATETIME - The DATETIME type follows the standard format YYYY-MM-DD hh:mm
TIMESTAMP - The TIMESTAMP type also follows the same format of DATETIME i.e. YYYY-MM-DD hh:mm
TIME - The TIME type follows the standard format hh:mm
YEAR - 1-byte type used to represent the year values.
|Type||Format||Min Value||Max Value|
||1000-01-01 00:00:00||9999-12-31 23:59:59|
||1970-01-01 00:00:01||2038-01-19 03:14:07|
|YEAR||1 Or 2 Digit||1||99|
- The TIMESTAMP values will be stored in UTC.
- The data types DATETIME, TIMESTAMP, and TIME also support 6 digits fractional values ranging from 000000 to 999999.
- MySQL converts 1 Or 2 Digit YEAR values in the ranges from 1 to 69 and 70 to 99 to YEAR values in the ranges from 2001 to 2069 and 1970 to 1999 respectively.
The string data types include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, TEXT, ENUM, and SET types.
CHAR and VARCHAR Types
CHAR and VARCHAR data types can be used to store string values.
CHAR - Length can be any value from 0 to 255 characters. The length of CHAR column will be fixed to the length specified while declaring the column. In case the value occupies fewer characters, it will be right-padded with spaces to fully consume the length of 255 characters. The value will also be truncated if it consists of more than 255 characters.
VARCHAR - Length can be any value from 0 to 65,535 characters subject to a maximum row size of 65,535 characters shared among all the columns. Values are stored as a 1-byte or 2-byte length prefix plus data. The value won't be padded by space and it will be truncated if it occupies more characters as compared to the column limit.
Comparison - Storing the string i.e. 'ab' in CHAR(4) will consume 4 bytes whereas VARCHAR(4) will consume only 3 bytes. The column length of CHAR remains same irrespective of actual value.
BINARY and VARBINARY Types
BINARY and VARBINARY data types can be used to store binary string values as compared to CHAR and VARCHAR which stores nonbinary string values. Both BINARY and VARBINARY data types will have the binary character set and collation, and comparison and sorting are based on the numeric values of the bytes in the values.
BINARY - Length can be any value from 0 to 255 bytes. Similar to CHAR, the length of the BINARY column will be fixed to the length specified while declaring the column.
VARBINARY - Length can be any value from 0 to 65,535 bytes.
BLOB and TEXT Types
TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB are the BLOB data types available in MySQL and used to store the variable amount of data. The BLOB values are treated as binary or byte strings.
TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT are the TEXT data types and used to store character strings.
The maximum length of these data types are as listed below:
|Binary Type||Nonbinary Type||Max Length||Max Space|
ENUM represents string object having a value from the possible values specified in the column specification while creating the table or table column.
The ENUM data type can be used to store data in a compact form where the actual value will be stored as encoded in number form. The corresponding string value will be returned while retrieving the value.
For example: Column definition - size ENUM('x-small', 'small', 'medium', 'large', 'x-large') - The size column having data type ENUM allows only the pre-defined values. We have to pass either of these values while adding or updating the column value.
SET can be used to store comma separated values from a definite set specified while creating the table or table column.
For example - A column specified as SET( 'Apple', 'Ball', 'Cat' ) can have below listed values:
Spatial Data Types
The spatial data types include single geometry value and collection of geometry value.
Single geometry values
GEOMETRY - Stores geometry values of any type.
POINT - Stores point values of a single point.
LINESTRING - Collection of points to form line having multiple points.
POLYGON - Collection of points to form a polygonal surface.
Collections of values
MULTIPOINT - Stores collection of multiple points.
MULTILINESTRING - Stores collection of multiple lines.
MULTIPOLYGON - Stores collection of multiple polygons.
GEOMETRYCOLLECTION - Stores collection of geometry values of any type.
JSON Data Type
The native JSON data type supported by MySQL can be used to directly store the JSON object. MySQL ensures that a valid JSON document gets stored in the JSON column.
These are all the data types available in MySQL relational database. It also supports document storage and operations on the stored documents using the JSON data type.