Skip to main content

MySQL / MariaDB

Overview

MySQL and MariaDB (a community fork) are popular relational databases for LAMP stacks, WordPress, and many SaaS products. They offer replication, storage engines (InnoDB is default), and broad hosting support—from managed cloud (RDS, PlanetScale) to self-hosted.

Key concepts

  • InnoDB — Row-level locking, foreign keys, transactions.
  • Replication — Primary/replica topologies; read scaling with staleness awareness.
  • Indexes — B-tree (default), full-text; EXPLAIN for query plans.
  • SQL dialect — Mostly standard SQL with MySQL-specific extensions.
  • Migrations — Schema versioning via tools (Flyway, Laravel migrations, etc.).

Read scaling (replicas)

Sample: InnoDB table + query

CREATE TABLE orders (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT NOT NULL,
total_cents INT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_orders_user (user_id)
) ENGINE=InnoDB;

SELECT id, total_cents
FROM orders
WHERE user_id = 1001
ORDER BY created_at DESC
LIMIT 20;

References