MySQL Cheat Sheets
Overview
Quick reference guides for common MySQL tasks and commands.
Available Cheat Sheets
1. SQL Basics Cheat Sheet
Topics covered:
- SELECT queries
- INSERT, UPDATE, DELETE
- WHERE clauses
- ORDER BY and LIMIT
- Aggregate functions
2. JOIN Operations Cheat Sheet
Topics covered:
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- CROSS JOIN
- Self JOIN
3. Data Types Cheat Sheet
Topics covered:
- Numeric types
- String types
- Date and time types
- JSON type
- ENUM and SET
4. Functions Cheat Sheet
Topics covered:
- String functions
- Date/time functions
- Math functions
- Aggregate functions
- Control flow functions
5. Index and Optimization Cheat Sheet
Topics covered:
- Creating indexes
- Index types
- EXPLAIN command
- Query optimization tips
6. User Management Cheat Sheet
Topics covered:
- Creating users
- Granting privileges
- Revoking privileges
- User security
7. Backup and Restore Cheat Sheet
Topics covered:
- mysqldump commands
- Import/export
- phpMyAdmin backup
- Automated backups
Quick Reference Cards
MySQL Command Line
# Connect to MySQL
mysql -u username -p
# Connect to specific database
mysql -u username -p database_name
# Connect to remote server
mysql -h hostname -u username -p
# Execute SQL file
mysql -u username -p database_name < file.sql
# Execute single command
mysql -u username -p -e "SHOW DATABASES;"
# Dump database
mysqldump -u username -p database_name > backup.sql
# Dump all databases
mysqldump -u username -p --all-databases > all_backup.sql
Common SQL Commands
-- DATABASE
CREATE DATABASE dbname;
DROP DATABASE dbname;
USE dbname;
SHOW DATABASES;
-- TABLES
CREATE TABLE tablename (...);
DROP TABLE tablename;
ALTER TABLE tablename ...;
SHOW TABLES;
DESCRIBE tablename;
-- DATA
SELECT * FROM tablename;
INSERT INTO tablename VALUES (...);
UPDATE tablename SET ... WHERE ...;
DELETE FROM tablename WHERE ...;
-- USERS
CREATE USER 'user'@'host' IDENTIFIED BY 'password';
GRANT privileges ON db.* TO 'user'@'host';
REVOKE privileges ON db.* FROM 'user'@'host';
DROP USER 'user'@'host';
Data Types Quick Reference
-- NUMERIC
TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT
DECIMAL(M,D), FLOAT, DOUBLE
-- STRING
CHAR(M), VARCHAR(M)
TEXT, MEDIUMTEXT, LONGTEXT
ENUM('val1','val2',...)
-- DATE/TIME
DATE, TIME, DATETIME, TIMESTAMP, YEAR
-- OTHER
BOOLEAN (TINYINT(1))
JSON
JOIN Types Visual
INNER JOIN: A ∩ B (intersection)
LEFT JOIN: A ∪ (A ∩ B) (all A + matching B)
RIGHT JOIN: (A ∩ B) ∪ B (matching A + all B)
CROSS JOIN: A × B (cartesian product)
Downloadable PDFs (Coming Soon)
- MySQL Basics (1 page)
- Advanced SQL (2 pages)
- Performance Tuning (1 page)
- Security Checklist (1 page)
Interactive Cheat Sheets
For interactive cheat sheets, visit:
Contributing
Have improvements or additions to the cheat sheets? See CONTRIBUTING.md.
License
These cheat sheets are part of the MySQL-WAMP-XAMPP-Tutorial project and follow the same MIT License.