MySQL Data Types
MySQL supports various data types to store different types of data in a database.
These data types can be broadly categorized into the following groups:
-
Numeric Data Types:
- TINYINT: A small integer type, typically used for storing small numbers.
- SMALLINT: A medium-sized integer type.
- INT or INTEGER: A standard integer type.
- BIGINT: A large integer type.
- DECIMAL or NUMERIC: Used for exact numeric values with a specified number of digits before and after the decimal point.
- FLOAT: A single-precision floating-point number.
- DOUBLE: A double-precision floating-point number.
-
String Data Types:
- CHAR: Fixed-length character string.
- VARCHAR: Variable-length character string.
- TEXT: Used for large text data.
- ENUM: Enumerated type, allowing you to store one of a predefined list of values.
- SET: Similar to ENUM, but allows for multiple values to be selected from a predefined list.
-
Date and Time Data Types:
- DATE: Stores a date (YYYY-MM-DD).
- TIME: Stores a time (HH:MM:SS).
- DATETIME: Stores both date and time (YYYY-MM-DD HH:MM:SS).
- TIMESTAMP: A timestamp, typically used to store the date and time of record creation or modification.
- YEAR: Stores a four-digit year value.
-
Binary Data Types:
- BINARY: Fixed-length binary data.
- VARBINARY: Variable-length binary data.
- BLOB: Binary Large Object, used for storing large binary data like images or files.
-
Spatial Data Types:
- GEOMETRY: Stores geometric shapes.
- POINT: Stores a single point in space.
- LINESTRING: Stores a single line.
- POLYGON: Stores a polygon.
- MULTIPOINT: Stores a set of points.
- MULTILINESTRING: Stores a set of lines.
- MULTIPOLYGON: Stores a set of polygons.
- GEOMETRYCOLLECTION: Stores a collection of geometry objects.
-
JSON Data Types:
- JSON: Stores JSON (JavaScript Object Notation) data.
-
Other Data Types:
- BOOLEAN: A synonym for TINYINT(1), typically used for boolean values (0 or 1).
- SERIAL: An alias for an auto-incrementing integer column.
It's important to choose the appropriate data type for each column in your database schema to ensure efficient storage and retrieval of data.
The choice of data type depends on the nature of the data you need to store and the constraints you want to enforce on that data.
MySQL Data Types
Enroll Now