MySQL is an open-source relational database management system (RDBMS) that uses Structured Query Language (SQL) for managing and querying data. As one of the world's most popular database systems, MySQL powers everything from small web applications to large-scale enterprise systems, offering ACID-compliant transactions, replication, and high availability features. MySQL 8.4 is the current Long-Term Support (LTS) release, bringing improvements to JSON handling, window functions, LATERAL derived tables, and role-based access control while removing legacy master/slave replication terminology. A critical distinction to understand: while MySQL supports multiple storage engines, InnoDB (the default since MySQL 5.5) provides row-level locking and foreign key constraints, whereas the legacy MyISAM uses table-level locking—choosing the right engine and understanding isolation levels can make the difference between a responsive system and one plagued by deadlocks.
What This Cheat Sheet Covers
This topic spans 38 focused tables and 306 indexed concepts, 170 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Data Types
Picking the right column type is the first design decision in any schema, and it has lasting consequences for storage, speed, and correctness. The recurring tension here is exactness versus efficiency — use DECIMAL for money where rounding errors are unacceptable, INT/BIGINT sized to your real range, and VARCHAR over CHAR unless the length is genuinely fixed. Note also the timezone trap: DATETIME stores a wall-clock value while TIMESTAMP converts to and from UTC.
| Type | Example | Description | |
|---|---|---|---|
id INT PRIMARY KEY | • Integer range -2,147,483,648 to 2,147,483,647 (signed) • 4 bytes. | ||
name VARCHAR(100) | • Variable-length string • only uses space needed plus 1–2 bytes for length • max 65,535 chars. | ||
description TEXT | • Variable-length string for large text blocks • max 65,535 chars • cannot have a default value or be a primary key. | ||
price DECIMAL(10,2) | • Fixed-point number with exact precision • first param = total digits, second = decimal places • ideal for currency. | ||
birth_date DATE | • Stores date only in YYYY-MM-DD format• range 1000-01-01 to 9999-12-31. | ||
created_at DATETIME | • Stores date and time in YYYY-MM-DD HH:MM:SS• range up to 9999-12-31 23:59:59• not timezone-aware. | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | • Stores datetime with automatic timezone conversion • range 1970-01-01 to 2038-01-19 UTC• auto-updates on modification. | ||
is_active BOOLEAN | • Synonym for TINYINT(1) • stores 0 (false) or 1 (true) • MySQL converts TRUE/FALSE to 1/0. | ||
user_id BIGINT | • Large integer • 8 bytes • range ±9.2×10¹⁸ • used for large auto-increment IDs and big counts. | ||
metadata JSON | • Native JSON type • validates JSON syntax • supports path expressions and indexing via generated columns. | ||
status ENUM('pending', 'active', 'closed') | • String with predefined allowed values • stored internally as integers • max 65,535 distinct values. | ||
country_code CHAR(2) | • Fixed-length string • always uses full allocated length (padded with spaces) • faster than VARCHAR for fixed-size data. | ||
score FLOAT | • Approximate floating-point • 4 bytes • precision can be lost in calculations • faster than DECIMAL. | ||
latitude DOUBLE | • Double-precision floating-point • 8 bytes • higher precision than FLOAT but still approximate. | ||
age TINYINT UNSIGNED | • Smallest integer • 1 byte • range -128 to 127 (signed) or 0 to 255 unsigned • common for flags and small counts. | ||
quantity SMALLINT | • 2-byte integer • range -32,768 to 32,767 (signed) • good for moderate-range integers saving space vs INT. | ||
page_views MEDIUMINT | • 3-byte integer • range ±8.4 million • between SMALLINT and INT in size and range. | ||
image BLOB | • Binary large object • stores binary data • four sizes: TINYBLOB (255B), BLOB (64KB), MEDIUMBLOB (16MB), LONGBLOB (4GB). | ||
body MEDIUMTEXT | • MEDIUMTEXT: up to 16MB of text • LONGTEXT: up to 4GB of text; both cannot have defaults. | ||
duration TIME | • Stores time in HH:MM:SS• range -838:59:59 to 838:59:59• represents time intervals as well as time of day. | ||
perms SET('read','write','exec') | • String object that can hold zero or more values from a predefined list • stored as a bitmask • max 64 members. | ||
grad_year YEAR | • Stores a 4-digit year (1901–2155) • 1 byte • displays as YYYY. |