A Data Type specifies a particular type of data, like integer, floating points, Boolean etc. It also identifies the possible values for that type, the operations that can be performed on that type and the way the values of that type are stored.
MySQL supports a lot number of SQL standard data types in various categories. It uses many different data types broken into mainly three categories: numeric, date and time, and string types.
Data Type Syntax | Description |
---|---|
INT | A normal-sized integer that can be signed or unsigned. If signed, the allowable range is from -2147483648 to 2147483647. If unsigned, the allowable range is from 0 to 4294967295. You can specify a width of up to 11 digits. |
TINYINT | A very small integer that can be signed or unsigned. If signed, the allowable range is from -128 to 127. If unsigned, the allowable range is from 0 to 255. You can specify a width of up to 4 digits. |
SMALLINT | A small integer that can be signed or unsigned. If signed, the allowable range is from -32768 to 32767. If unsigned, the allowable range is from 0 to 65535. You can specify a width of up to 5 digits. |
MEDIUMINT | A medium-sized integer that can be signed or unsigned. If signed, the allowable range is from -8388608 to 8388607. If unsigned, the allowable range is from 0 to 16777215. You can specify a width of up to 9 digits. |
BIGINT | A large integer that can be signed or unsigned. If signed, the allowable range is from -9223372036854775808 to 9223372036854775807. If unsigned, the allowable range is from 0 to 18446744073709551615. You can specify a width of up to 20 digits. |
FLOAT(m,d) | A floating-point number that cannot be unsigned. You can define the display length (m) and the number of decimals (d). This is not required and will default to 10,2, where 2 is the number of decimals and 10 is the total number of digits (including decimals). Decimal precision can go to 24 places for a float. |
DOUBLE(m,d) | A double precision floating-point number that cannot be unsigned. You can define the display length (m) and the number of decimals (d). This is not required and will default to 16,4, where 4 is the number of decimals. Decimal precision can go to 53 places for a double. Real is a synonym for double. |
DECIMAL(m,d) | An unpacked floating-point number that cannot be unsigned. In unpacked decimals, each decimal corresponds to one byte. Defining the display length (m) and the number of decimals (d) is required. Numeric is a synonym for decimal. |
Data Type Syntax | Maximum Size | Explanation |
---|---|---|
DATE | Values range from '1000-01-01' to '9999-12-31'. | Displayed as 'yyyy-mm-dd'. |
DATETIME | Values range from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. | Displayed as 'yyyy-mm-dd hh:mm:ss'. |
TIMESTAMP(m) | Values range from '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' TC. | Displayed as 'YYYY-MM-DD HH:MM:SS'. |
TIME | Values range from '-838:59:59' to '838:59:59'. | Displayed as 'HH:MM:SS'. |
YEAR[(2|4)] | Year value as 2 digits or 4 digits. | Default is 4 digits. |
Data Type Syntax | Maximum Size | Explanation |
---|---|---|
CHAR(size) | Maximum size of 255 characters. | Where size is the number of characters to store. Fixed-length strings. Space padded on right to equal size characters. |
VARCHAR(size) | Maximum size of 255 characters. | Where size is the number of characters to store. Variable-length string. |
TINYTEXT(size) | Maximum size of 255 characters. | Where size is the number of characters to store. |
TEXT(size) | Maximum size of 65,535 characters. | Where size is the number of characters to store. |
MEDIUMTEXT(size) | Maximum size of 16,777,215 characters. | Where size is the number of characters to store. |
LONGTEXT(size) | Maximum size of 4GB or 4,294,967,295 characters. | Where size is the number of characters to store. |
BINARY(size) | Maximum size of 255 characters. | Where size is the number of binary characters to store. Fixed-length strings. Space padded on right to equal size characters. (introduced in MySQL 4.1.2) |
VARBINARY(size) | Maximum size of 255 characters. |
Where size is the number of characters to store. Variable-length string. (introduced in MySQL 4.1.2) |
Data Type Syntax | Maximum Size |
TINYBLOB | Maximum size of 255 bytes. |
BLOB(size) | Maximum size of 65,535 bytes. |
MEDIUMBLOB | Maximum size of 16,777,215 bytes. |
LONGTEXT | Maximum size of 4gb or 4,294,967,295 characters. |