MySQL
MySQL is the world's most popular open-source relational database, powering everything from WordPress sites to large platforms. It offers structured storage, SQL querying, and ACID transactions (via InnoDB) with a reputation for speed, reliability, and ease of use.
It's the database half of the classic LAMP/LEMP stack, and its ubiquity means broad hosting support, tooling, and community knowledge. For read-heavy web applications, it's a safe, well-trodden choice.
TL;DR
- A relational database using SQL, with InnoDB as the default ACID engine.
- Excellent for read-heavy web apps and widely supported everywhere.
- Use transactions for multi-step writes and indexes for query speed.
- MariaDB is a drop-in-ish community fork worth knowing about.
Quick Example
A join pulls related rows from two tables — the everyday bread and butter of SQL:
Core Concepts
- Tables, keys, constraints — rows and columns with primary/foreign keys.
- InnoDB — the default storage engine: ACID transactions, row-level locking, foreign keys.
- Transactions —
BEGIN/COMMIT/ROLLBACKgroup writes atomically. - Indexes — speed up reads on filtered/joined columns (at a write cost).
- JOINs — combine rows across related tables.
💡
CHARis fixed-length,VARCHARis variable-length;NULLis the absence of a value, not0or''.
Best Practices
- Use InnoDB (the default) for transactions and foreign keys — not the legacy MyISAM.
- Add indexes to columns used in
WHEREandJOIN; avoid over-indexing. - Always use parameterized queries to prevent SQL injection.
- Profile with
EXPLAIN; wrap multi-step writes in transactions.
Comparison: MySQL vs PostgreSQL
See PostgreSQL.
Common Mistakes
Using MyISAM instead of InnoDB
DELETE/UPDATE without a WHERE
FAQ
MySQL or PostgreSQL?
MySQL is a great fit for read-heavy web apps, broad hosting support, and teams already familiar with it. PostgreSQL pulls ahead for complex queries, JSON, extensions, and strict standards compliance. Both are excellent; pick based on your workload and ecosystem.
InnoDB or MyISAM?
InnoDB, in essentially all cases — it provides ACID transactions, row-level locking, and foreign keys. MyISAM is legacy; its only edge was older full-text search, which InnoDB now supports too.
What's the difference between MySQL and MariaDB?
MariaDB is a community-driven fork of MySQL created after Oracle's acquisition, aiming for compatibility plus extra features and engines. For most apps they're interchangeable, but verify compatibility for advanced or version-specific features.
When should I not use MySQL?
For document/unstructured data (MongoDB), time-series (TimescaleDB/InfluxDB), graph relationships (Neo4j), or analytics over huge datasets (ClickHouse, BigQuery). For everyday relational web data, MySQL is well-suited.
Related Topics
- PostgreSQL — The other popular RDBMS
- SQL Fundamentals — The query language
- Database Indexing — Query performance
- Database Replication — Scaling reads and HA
- Redis — Caching in front of MySQL