rss feed Twitter Page Facebook Page Github Page Stack Over Flow Page

MySQL Field Types

MySQL supports a number of column types, which may be grouped into three main categories:

This section first gives an overview of the types available and how much space (in bytes) they takes.

For more information, please refer to the MySQL manuals for more details.

Type Range Size
TINYINT The signed range is -128 to 127. The unsigned range is 0 to 255. 1 byte
SMALLINT The signed range is -32,768 to 32,767. The unsigned range is 0 to 65,535 2 bytes
MEDIUMINT The signed range is -8,388,608 to 8,388,607. The unsigned range is 0 to 16,777,215 3 bytes
INT or INTEGER The signed range is -2,147,483,648 to 2,147,483,647. The unsigned range is 0 to 4,294,967,295 4 bytes
BIGINT The signed range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The unsigned range is 0 to 18,446,744,073,709,551,615 8 bytes
FLOATCannot be unsigned Ranges are -3.402823466E+38 to -1.175494351E-38, 0 and 1.175494351E-38 to 3.402823466E+38. If the number of Decimals is not set or <= 24 it is a single-precision floating point number 4 bytes
DOUBLE, DOUBLE PRECISION, REALCannot be unsigned Ranges are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0 and 2.2250738585072014E-308 to 1.7976931348623157E+308. If the number of Decimals is not set or 25 <= Decimals <= 53 stands for a double-precision floating point number 8 bytes
DECIMAL, NUMERICCannot be unsigned Behaves like a CHAR column: "unpacked" means the number is stored as a string, using one character for each digit of the value. The decimal point, and, for negative numbers, the '-' sign is not counted in Length. If Decimals is 0, values will have no decimal point or fractional part. The maximum range of DECIMAL values is the same as for DOUBLE, but the actual range for a given DECIMAL column may be constrained by the choice of Length and Decimals. If Decimals is left out it's set to 0. If Length is left out it's set to 10. Note that in MySQL 3.22 the Length includes the sign and the decimal point M + 2 bytes
Type Format Zero Values Size
DATE The supported range is '1000-01-01' to '9999-12-31'. MySQL displays DATE values in 'YYYY-MM-DD' format 0000-00-00 3 bytes
DATETIME The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. MySQL displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format 0000-00-00 00:00:00 8 bytes
TIME The range is '-838:59:59' to '838:59:59'. MySQL displays TIME values in 'HH:MM:SS' format, but allows you to assign values to TIME columns using either strings or numbers 00:00:00 3 bytes
TIMESTAMP The range is '1970-01-01 00:00:00' to sometime in the year 2037. MySQL displays TIMESTAMP values in YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD or YYMMDD format, depending on whether M is 14 (or missing), 12, 8 or 6, but allows you to assign values to TIMESTAMP columns using either strings or numbers. A TIMESTAMP column is useful for recording the date and time of an INSERT or UPDATE operation because it is automatically set to the date and time of the most recent operation if you don't give it a value yourself 0000000000 4 bytes
YEAR The allowable values are 1901 to 2155, and 0000 in the 4-year format and 1970-2069 if you use the 2 digit format (70-69). MySQL displays YEAR values in YYYY format, but allows you to assign values to YEAR columns using either strings or numbers. (The YEAR type is new in MySQL 3.22.) 0000 1 byte
Type Range Size
CHAR The range of Length is 1 to 255 characters. CHAR values are sorted and compared in case-insensitive fashion according to the default character set unless the BINARY keyword is given. x bytes
VARCHAR The range of Length is 1 to 255 characters. VARCHAR values are sorted and compared in case-insensitive fashion unless the BINARY keyword is given. x+1 bytes
VARCHAR The range of Length is > 255 characters. VARCHAR values are sorted and compared in case-insensitive fashion unless the BINARY keyword is given. x+2 bytes
TINYBLOB, TINYTEXT A BLOB or TEXT column with a maximum length of 255 (2^8 - 1) characters x+1 bytes
BLOB, TEXT A BLOB or TEXT column with a maximum length of 65535 (2^16 - 1) characters x+2 bytes
MEDIUMBLOB, MEDIUMTEXT A BLOB or TEXT column with a maximum length of 16777215 (2^24 - 1) characters x+3 bytes
LONGBLOB, LONGTEXT A BLOB or TEXT column with a maximum length of 4294967295 (2^32 - 1) characters x+4 bytes
Type Range Size
ENUM A string object that can have only one value, chosen from the list of values 'value1', 'value2', ..., or NULL. An ENUM can have a maximum of 65535 distinct values. 1 or 2 bytes, depending on the number of enumeration values (65,535 values maximum)
SET A string object that can have zero or more values, each of which must be chosen from the list of values 'value1', 'value2', ... A SET can have a maximum of 64 members 1, 2, 3, 4, or 8 bytes, depending on the number of set members (64 members maximum)