Data type defines the type of data entered by the user. While defining the fields of table we have to mention proper data type along with its size.
MySQL uses many different data types like: integer, real, date-time, string etc.
Numeric data type contain numeric value without decimal.
Data Type | Size | Description |
---|---|---|
TINYINT | 1 byte | Range of -128 to 127 or 0 to 255 unsigned. |
SMALLINT | 2 bytes | Range of -32,768 to 32,767 or 0 to 65535 unsigned. |
MEDIUMINT | 3 bytes | Range of -8,388,608 to 8,388,607 or 0 to 16,777,215 unsigned. |
INT | 4 bytes | Range of -2,147,483,648 to 2,147,483,647 or 0 to 4,294,967,295 unsigned. |
BIGINT | 8 bytes | Range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 or 0 to 18,446,744,073,709,551,615 unsigned. |
Decimal data type contain numeric as well as decimal value.
Data Type | Size | Description |
---|---|---|
FLOAT | 4 bytes | A small number with a floating decimal point. |
DOUBLE[Length, Decimals] | 8 bytes | A large number with a floating decimal point. |
Data-Time data type contain date as well as time value.
Data Type | Size | Description |
---|---|---|
DATE | 3 bytes | Format is YYYY-MM-DD. |
DATETIME | 8 bytes | Format is YYYY-MM-DD HH:MM:SS. |
TIME | 3 bytes | Format is HH:MM:SS |
String data type contain alpha numeric data type.
Data Type | Size | Description |
---|---|---|
CHAR[Length] | Length bytes | A fixed-length from 0 to 255 characters long. |
VARCHAR(Length) | String length + 1 byte | Variable-length strings with a maximum size of 65,535 characters. |