MySQL Data Types
When working with databases, data types are extremely important because they determine what kind of values can be stored in each column of a table. MySQL provides a wide range of data types, and each one has its own characteristics related to storage, indexing, and value comparison.
Selecting the appropriate data type can help improve database performance, reduce unnecessary storage usage, and maintain data integrity.
Table of Contents

Complete Advance AI Topics: Click Here
SQL Tutorial: Click Here
Characteristics of MySQL Data Types
When choosing a data type for a particular column, several factors should be considered:
- The kind of values it represents, whether they have fixed or variable length.
- The amount of storage space required.
- Whether the stored values can be indexed.
- How MySQL compares and processes values of that particular type.
MySQL data types can be grouped into the following categories:
- Numeric Data Types
- Date and Time Data Types
- String Data Types
- Binary Large Object (BLOB) Data Types
- Spatial Data Types
- JSON Data Type
1. Numeric Data Types
MySQL supports both exact and approximate numeric data types. This provides flexibility when working with numbers that require different levels of precision.
| Data Type | Description |
|---|---|
| SMALLNUM | A small integer value with a signed range of -32,768 to 32,767 and an unsigned range of 0 to 65,535. It requires 2 bytes of storage. |
| MIDNUM | A medium-sized integer with a signed range of -8,388,608 to 8,388,607 and an unsigned range of 0 to 16,777,215. It requires 3 bytes. |
| WHOLEINT | A standard integer with a signed range of -2,147,483,648 to 2,147,483,647 and an unsigned range of 0 to 4,294,967,295. It requires 4 bytes. |
| GIANTNUM | A large integer with a signed range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and an unsigned range of 0 to 18,446,744,073,709,551,615. It requires 8 bytes. |
| FRACTION | A floating-point number with adjustable precision, typically storing decimal values up to 24 digits. It uses 4 bytes. |
| DOUBLEVAL | A double-precision floating-point number that provides higher decimal accuracy and uses 8 bytes. |
| FIXEDDEC | A decimal type designed to maintain precision and is typically used for financial calculations. Storage depends on the precision. |
| BITFIELD | Used for storing bit values and supports between 1 and 64 bits per value. |
| YESNO | A Boolean representation where 1 represents true and 0 represents false. |
2. Date and Time Data Types
Date and time data types are used to store temporal information, including dates, times, and timestamps.
| Data Type | Description |
|---|---|
| YRFORMAT | Stores year values in either 2-digit or 4-digit format. The default is 4 digits and it requires 1 byte. |
| DAYCOUNT | Stores dates in the YYYY-MM-DD format. Its range is from 1000-01-01 to 9999-12-31 and it requires 3 bytes. |
| HRSMINS | Stores time values in HH:MM:SS format. Its range is from -838:59:59 to 838:59:59 and requires 3+ bytes. |
| FULLTIME | Stores both date and time in YYYY-MM-DD HH:MM:SS format and requires 5+ bytes. |
| SNAPSHOT | Stores timestamp values ranging from 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. It uses 4+ bytes. |
3. String Data Types
String data types are used for storing textual information and binary content. They also support indexing and pattern matching.
| Data Type | Description |
|---|---|
| FIXTEXT | A fixed-length string with a maximum of 255 characters. Shorter values are padded with spaces. |
| VARTEXT | A variable-length string with a maximum of 255 characters. It uses only the required storage space. |
| TINYWORDS | A small text field that can contain up to 255 characters. |
| BIGWORDS | A large text field with a maximum size of 65,535 characters. |
| MEDWORDS | A medium-sized text field that can store up to 16,777,215 characters. |
| HUGEWORDS | An extra-large text field with a maximum capacity of 4GB. |
| BINDATA | A fixed-length binary data type with a maximum size of 255 bytes. |
| FLEXBIND | A variable-length binary data type with a maximum size of 255 bytes. |
| CHOICES | Stores a single value selected from a predefined list containing up to 65,535 options. |
| MULTICHO | Stores multiple values from a predefined list with up to 64 choices. |
4. Binary Large Object (BLOB) Data Types
BLOB data types are used for storing large binary information, such as files and images.
| Data Type | Description |
|---|---|
| SMALLBIN | Stores up to 255 bytes of binary data. |
| MEDBIN | Stores up to 65,535 bytes of binary data. |
| BIGBIN | Stores up to 16,777,215 bytes of binary data. |
| HUGEFILE | Stores up to 4GB of binary data. |
5. Spatial Data Types
Spatial data types are designed to store geometric and geographic information.
| Data Type | Description |
|---|---|
| LOCSPOT | Stores a single location point using X and Y coordinates. |
| ROADPATH | Represents a series of connected points that form a line. |
| REGIONMAP | Defines a multisided area or polygon on a map. |
| MULTILINE | Stores multiple line segments together. |
| MULTISPOT | Stores multiple individual point locations. |
| MULTIAREA | Stores multiple polygon regions. |
6. JSON Data Type
MySQL provides native JSON support, which can be used for efficient storage and retrieval of JSON documents.
Advantages of JSON Data Type
- Provides automatic validation of JSON documents and rejects invalid data.
- Uses an optimized storage format compared with storing JSON in string columns.
- Provides quick and efficient access to individual JSON elements.
Download New Real Time Projects :- Click here
Conclusion
Choosing the correct MySQL data type is an important part of designing and optimizing a database. Numeric types are used for efficient number storage, date and time types handle temporal information, string and BLOB types store text and binary content, spatial types manage geographical information, and JSON provides a convenient way to work with structured data.
A proper understanding of MySQL data types can lead to better database design, improved query performance, and stronger data integrity. Whenever you create a MySQL table, selecting the appropriate data type for each column is essential.
SEO Keywords
mysql data types in hindi, mysql data types in php, mysql data types with examples, mysql data types w3schools, mssql data types, mysql data types pdf, data types in mysql geeksforgeeks, postgresql data types, mysql data types, explain mysql data types, prisma mysql data types, mysql data types text, mysql data types boolean, mysql data types numeric, mysql data types cheat sheet, mysql data types in hindi