MySQL
Overview
MySQL is a widely deployed open-source relational database maintained by Oracle, known for speed, reliability, and broad ecosystem support. Read this when building on a MySQL backend: designing tables, choosing storage engines, writing SQL, or configuring replication.
Official sources
Install / setup
On Debian/Ubuntu, MySQL provides the APT Repository (mysql-apt-config) from dev.mysql.com/downloads/. The Community Server, MySQL Shell, MySQL Router, and Workbench are listed there. On macOS the recommended path is via the MySQL Installer / DMG, and on Windows via the MySQL Installer for Windows.
# After installing the APT repo config package from dev.mysql.com/downloads/repo/apt/
sudo apt update
sudo apt install mysql-server
(Follow the exact repo-config steps on the official APT Repository download page for your distribution.)
Core concepts
- Relational model with ACID transactions when using a transactional storage engine.
- Storage engines: InnoDB (default, transactional, row-level locking, foreign keys) vs MyISAM (non-transactional, table locks).
- Indexes: B-tree by default; covering, composite, and full-text indexes available.
- Replication: source/replica (formerly master/slave) for read scaling and availability.
- Character sets and collations: use
utf8mb4 for full Unicode (including emoji).
- The
mysql client and MySQL Shell for administration and scripting.
Best practices
- Use the InnoDB storage engine for transactional integrity and crash recovery (it's the default).
- Use
utf8mb4 character set rather than the legacy utf8 (which is limited to 3-byte sequences).
- Add appropriate indexes and verify with
EXPLAIN; avoid functions on indexed columns in WHERE clauses.
- Define explicit foreign keys and constraints under InnoDB to enforce referential integrity.
- Run
mysql_secure_installation to harden a fresh server.
Common pitfalls
- Choosing
utf8 and later hitting 4-byte character failures → use utf8mb4 from the start.
- Relying on MyISAM for data that needs transactions or crash safety → use InnoDB.
- Wrapping indexed columns in functions (e.g.,
WHERE DATE(col) = ...) → prevents index use.
- Assuming default isolation; MySQL/InnoDB defaults to REPEATABLE READ → know the level your app needs.
Examples
CREATE TABLE users (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY uq_email (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Further reading
Related skills
- ../mariadb — community-driven MySQL fork
- ../planetscale — managed MySQL-compatible (Vitess) platform
- ../postgresql — alternative open-source RDBMS
1---2name: mysql3description: Popular open-source relational database from Oracle; consult for schema design, SQL, storage engines (InnoDB), and replication.4domain: stack5category: database6tags: [mysql, sql, rdbms, relational, innodb]7official_sources:8 - https://dev.mysql.com/doc/9 - https://github.com/mysql/mysql-server10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/mysql13---1415# MySQL1617## Overview18MySQL is a widely deployed open-source relational database maintained by Oracle, known for speed, reliability, and broad ecosystem support. Read this when building on a MySQL backend: designing tables, choosing storage engines, writing SQL, or configuring replication.1920## Official sources21- Docs: https://dev.mysql.com/doc/22- Repo (official, Oracle): https://github.com/mysql/mysql-server23- Install / download: https://dev.mysql.com/downloads/2425## Install / setup26On Debian/Ubuntu, MySQL provides the APT Repository (mysql-apt-config) from dev.mysql.com/downloads/. The Community Server, MySQL Shell, MySQL Router, and Workbench are listed there. On macOS the recommended path is via the MySQL Installer / DMG, and on Windows via the MySQL Installer for Windows.2728```bash29# After installing the APT repo config package from dev.mysql.com/downloads/repo/apt/30sudo apt update31sudo apt install mysql-server32```3334(Follow the exact repo-config steps on the official APT Repository download page for your distribution.)3536## Core concepts37- Relational model with ACID transactions when using a transactional storage engine.38- Storage engines: InnoDB (default, transactional, row-level locking, foreign keys) vs MyISAM (non-transactional, table locks).39- Indexes: B-tree by default; covering, composite, and full-text indexes available.40- Replication: source/replica (formerly master/slave) for read scaling and availability.41- Character sets and collations: use `utf8mb4` for full Unicode (including emoji).42- The `mysql` client and MySQL Shell for administration and scripting.4344## Best practices45- Use the InnoDB storage engine for transactional integrity and crash recovery (it's the default).46- Use `utf8mb4` character set rather than the legacy `utf8` (which is limited to 3-byte sequences).47- Add appropriate indexes and verify with `EXPLAIN`; avoid functions on indexed columns in WHERE clauses.48- Define explicit foreign keys and constraints under InnoDB to enforce referential integrity.49- Run `mysql_secure_installation` to harden a fresh server.5051## Common pitfalls52- Choosing `utf8` and later hitting 4-byte character failures → use `utf8mb4` from the start.53- Relying on MyISAM for data that needs transactions or crash safety → use InnoDB.54- Wrapping indexed columns in functions (e.g., `WHERE DATE(col) = ...`) → prevents index use.55- Assuming default isolation; MySQL/InnoDB defaults to REPEATABLE READ → know the level your app needs.5657## Examples58```sql59CREATE TABLE users (60 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,61 email VARCHAR(255) NOT NULL,62 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,63 UNIQUE KEY uq_email (email)64) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;65```6667## Further reading68- The InnoDB storage engine: https://dev.mysql.com/doc/refman/en/innodb-storage-engine.html69- Optimization: https://dev.mysql.com/doc/refman/en/optimization.html7071## Related skills72- ../mariadb — community-driven MySQL fork73- ../planetscale — managed MySQL-compatible (Vitess) platform74- ../postgresql — alternative open-source RDBMS