All tools
Free

A searchable, printable MySQL reference — queries, joins, indexes, functions, data types and administration commands. Free.

Querying

10
SELECT * FROM users;
Select all columns and rows
SELECT id, name FROM users;
Select specific columns
SELECT DISTINCT city FROM users;
Unique values only
WHERE age > 18 AND active = 1
Filter rows by conditions
WHERE name LIKE 'A%'
Pattern match (% = any chars)
WHERE id IN (1, 2, 3)
Match any value in a set
WHERE age BETWEEN 18 AND 30
Inclusive range filter
ORDER BY created_at DESC
Sort descending
LIMIT 10 OFFSET 20
Paginate results
WHERE email IS NULL
Match null values

Joins

8
INNER JOIN orders ON orders.user_id = users.id
Rows matching in both tables
LEFT JOIN orders ON ...
All left rows + matches
RIGHT JOIN orders ON ...
All right rows + matches
CROSS JOIN colors
Cartesian product
SELF JOIN: FROM emp e JOIN emp m ON e.mgr = m.id
Join a table to itself
USING (user_id)
Join on a same-named column
UNION / UNION ALL
Combine result sets
SELECT u.*, o.total FROM users u JOIN orders o
Alias tables for clarity

Aggregation

9
COUNT(*)
Count rows
SUM(amount)
Total of a numeric column
AVG(price)
Average value
MIN(price), MAX(price)
Smallest and largest
GROUP BY country
Group rows for aggregation
HAVING COUNT(*) > 5
Filter on aggregated groups
GROUP_CONCAT(name)
Concatenate grouped values
COUNT(DISTINCT city)
Count unique values
ROW_NUMBER() OVER (ORDER BY id)
Window function ranking

Modifying data

8
INSERT INTO users (name) VALUES ('Sam');
Insert a single row
INSERT INTO users (name) VALUES ('A'),('B');
Insert multiple rows
UPDATE users SET active = 1 WHERE id = 5;
Update matching rows
DELETE FROM users WHERE id = 5;
Delete matching rows
TRUNCATE TABLE logs;
Remove all rows quickly
INSERT ... ON DUPLICATE KEY UPDATE
Upsert on a unique key
REPLACE INTO users ...
Delete + insert on conflict
INSERT IGNORE INTO ...
Skip rows that would error

Schema / DDL

9
CREATE TABLE users (id INT PRIMARY KEY);
Create a new table
AUTO_INCREMENT
Auto-numbering column
ALTER TABLE users ADD COLUMN age INT;
Add a column
ALTER TABLE users DROP COLUMN age;
Remove a column
ALTER TABLE users MODIFY name VARCHAR(100);
Change a column type
DROP TABLE IF EXISTS users;
Delete a table
FOREIGN KEY (user_id) REFERENCES users(id)
Reference another table
ON DELETE CASCADE
Cascade deletes to children
CREATE TABLE t2 LIKE t1;
Copy a table structure

Indexes & keys

8
PRIMARY KEY (id)
Unique row identifier
UNIQUE (email)
Enforce unique values
CREATE INDEX idx_name ON users (name);
Speed up lookups on a column
CREATE INDEX idx_ab ON t (a, b);
Composite (multi-column) index
DROP INDEX idx_name ON users;
Remove an index
FULLTEXT (body)
Full-text search index
EXPLAIN SELECT ...;
Show the query plan
SHOW INDEX FROM users;
List indexes on a table

Data types

9
INT, BIGINT, TINYINT
Integer types by size
DECIMAL(10, 2)
Exact fixed-point numbers
VARCHAR(255)
Variable-length string
TEXT, LONGTEXT
Large text blobs
DATE, DATETIME, TIMESTAMP
Date and time types
BOOLEAN (TINYINT(1))
True/false stored as 0/1
JSON
Native JSON document column
ENUM('a', 'b')
One of a fixed set of values
UNSIGNED
Non-negative numeric modifier

Type sizes & limits

20
TINYINT
1 byte: -128..127 (0..255 UNSIGNED)
SMALLINT
2 bytes: -32,768..32,767 (0..65,535)
MEDIUMINT
3 bytes: -8.39M..8.39M (0..16.78M)
INT
4 bytes: -2.15B..2.15B (0..4.29B)
BIGINT
8 bytes: ±9.22×10^18 (0..1.84×10^19)
DECIMAL(M, D)
Exact: M up to 65 digits, D up to 30
FLOAT / DOUBLE
4 / 8 bytes approximate floating point
CHAR(M)
Fixed length, 0..255 characters
VARCHAR(M)
0..65,535 bytes (shared 64KB row limit)
TINYTEXT
Up to 255 bytes (~255 chars)
TEXT
Up to 65,535 bytes (64 KB)
MEDIUMTEXT
Up to 16,777,215 bytes (16 MB)
LONGTEXT
Up to 4,294,967,295 bytes (4 GB)
BLOB types
TINY/—/MEDIUM/LONG: 255B..4GB (binary)
JSON
Stored as LONGBLOB, up to ~4 GB
ENUM / SET
ENUM: 65,535 members; SET: 64 members
DATE
1000-01-01 to 9999-12-31 (3 bytes)
DATETIME
1000 to 9999, microseconds (5–8 bytes)
TIMESTAMP
1970-01-01 to 2038-01-19 UTC (4 bytes)
TIME / YEAR
±838:59:59 / 1901..2155

Functions

9
NOW(), CURDATE()
Current datetime / date
DATE_FORMAT(d, '%Y-%m-%d')
Format a date
DATEDIFF(a, b)
Days between two dates
CONCAT(a, ' ', b)
Join strings
COALESCE(a, b, 'n/a')
First non-null value
IFNULL(x, 0)
Replace null with a default
CASE WHEN x > 0 THEN '+' ELSE '-' END
Conditional expression
CAST(x AS CHAR)
Convert a value type
ROUND(x, 2)
Round to decimals

Transactions & admin

9
START TRANSACTION;
Begin a transaction
COMMIT;
Persist the transaction
ROLLBACK;
Undo the transaction
SAVEPOINT sp1;
Set a rollback point
SHOW TABLES;
List tables in the database
DESCRIBE users;
Show a table structure
SHOW PROCESSLIST;
List running connections
GRANT ALL ON db.* TO 'u'@'%';
Grant user privileges
mysqldump -u root db > db.sql
Back up a database (CLI)

No entry matches “:q”.


About MySQL Cheat Sheet

This MySQL cheat sheet gathers the SQL you actually type into one searchable reference: querying, joins, aggregation, modifying data, schema and DDL statements, indexes and keys, data types with their sizes and limits, built-in functions, and transactions and administration commands.

It is useful both as a syntax reminder — the exact shape of a LEFT JOIN, an UPSERT or an ALTER TABLE — and as a lookup for the details nobody memorizes, like integer ranges, VARCHAR limits and which index type fits a query.

Like every cheat sheet in this group it is free and client-side: filter rows live with the search box, hop between sections with the sticky table of contents, copy any statement with one click and print the page for reference at your desk.

How to use MySQL Cheat Sheet

  1. Open the sheet and review the sections, from Querying and Joins through Schema / DDL to Transactions & admin.
  2. Search for a keyword such as JOIN, INDEX or GROUP BY to filter all snippets live.
  3. Jump to Data types or Type sizes & limits when you need storage details rather than syntax.
  4. Click a statement or its copy icon to copy the SQL to your clipboard.
  5. Use Print for a paper copy of the full MySQL reference.

Frequently asked questions

Ten sections covering querying, joins, aggregation, data modification, schema DDL, indexes and keys, data types, type sizes and limits, functions, and transactions plus administration commands — each as a copy-ready SQL snippet.

Yes. A dedicated section lists type sizes and limits — the integer ranges and string length caps you otherwise have to look up in the manual — next to the data types section itself.

Yes. Click the SQL snippet or the copy icon on its row and it is copied to your clipboard immediately.

Both. The search box filters every row as you type with a live match count, and the Print button outputs a clean version without the page chrome.

Yes, it is completely free and runs in your browser with no login.


Popular searches
mysql cheat sheet mysql commands list mysql data types mysql joins syntax mysql alter table syntax mysql index syntax mysql aggregate functions mysql sql reference
Need help?
Found an issue with this tool? Let our team know.
Report an issue

Add this free tool to your own website — copy and paste the code below.