
205 views
MySQL Data Types
MySQL supports a wide range of data types that allow you to store and manipulate different types of data efficiently. Here are some of the commonly used data types in MySQL:
- Numeric Data Types:
INT
orINTEGER
: A standard integer.TINYINT
: A very small integer.SMALLINT
: A small integer.MEDIUMINT
: A medium-sized integer.BIGINT
: A large integer.DECIMAL
orNUMERIC
: Fixed-point numbers.FLOAT
: A single-precision floating-point number.DOUBLE
: A double-precision floating-point number.
- Character String Data Types:
CHAR
: Fixed-length character strings.VARCHAR
: Variable-length character strings.TEXT
: Variable-length text strings (with a large storage capacity).ENUM
: A string object that can have one value chosen from a list of allowed values.
- Binary Data Types:
BINARY
: Fixed-length binary strings.VARBINARY
: Variable-length binary strings.BLOB
: Binary large objects for storing binary data (e.g., images).
- Date and Time Data Types:
DATE
: Date (YYYY-MM-DD).TIME
: Time (HH:MM:SS).DATETIME
: Date and time (YYYY-MM-DD HH:MM:SS).TIMESTAMP
: A timestamp that updates automatically (YYYY-MM-DD HH:MM:SS).YEAR
: A year in two-digit or four-digit format.
- Boolean Data Type:
BOOLEAN
orBOOL
: A true/false or 1/0 value.
- JSON Data Type:
JSON
: For storing JSON (JavaScript Object Notation) data.
- Spatial Data Types:
GEOMETRY
: For storing geometry values.POINT
: A single point in space.LINESTRING
: A curve with straight segments.POLYGON
: A closed polygon.GEOMETRYCOLLECTION
: A collection of geometries.
- Set Data Type:
SET
: A string object that can have zero or more values chosen from a list of allowed values.
- ENUM Data Type:
ENUM
: A string object that can have one value chosen from a list of allowed values.
These data types provide the flexibility to store various types of data efficiently in your MySQL database. It’s essential to choose the appropriate data type for each column to ensure efficient storage and retrieval of data. Additionally, MySQL also supports user-defined data types and custom types in some storage engines.