Two excellent relational databases - and the practical reasons to choose one over the other.
Both are mature, free, open-source relational databases that power enormous production systems, and the SQL you write for one is mostly valid in the other. The choice usually comes down to where you're hosting and how much you'll lean on advanced features.
| MySQL | PostgreSQL | |
|---|---|---|
| Shared hosting | Almost always included | Rarely offered |
| Managed services | Widely available | Widely available, plus Neon and Supabase |
| Licence | GPL (community edition), owned by Oracle | PostgreSQL licence (permissive) |
| JSON | JSON type with functions | JSONB - binary, indexable |
| Extensions | Limited | Rich: PostGIS, pgvector and many more |
| Strictness | Strict by default in modern versions | Strict, with rich types and constraints |
| Close relative | MariaDB (a compatible fork) | - |
This is often the deciding factor. Shared hosting plans almost universally include MySQL - or MariaDB, a fork that behaves the same for everyday use - with phpMyAdmin for managing it. PostgreSQL is rarely available there. Off shared hosting, both are easy: every major cloud provider offers both as managed services, and newer developer platforms such as Neon and Supabase are built specifically on PostgreSQL.
For a typical web app - users, posts, orders - both do everything you need, including transactions, foreign keys, joins, window functions and common table expressions.
PostgreSQL pulls ahead as needs grow more varied. Its JSONB type stores JSON in a binary format you can index and query efficiently, so you can mix structured columns with flexible data. Its extension system adds whole capabilities: PostGIS for geographic queries, pgvector for AI similarity search, and many more. It also has a richer set of data types (arrays, ranges, enums, UUIDs) and constraints.
| Task | MySQL | PostgreSQL |
|---|---|---|
| Auto-incrementing id | INT AUTO_INCREMENT | GENERATED ALWAYS AS IDENTITY |
| Quoting identifiers | `backticks` | "double quotes" |
| Insert-or-update | ON DUPLICATE KEY UPDATE | ON CONFLICT ... DO UPDATE |
| Get the inserted row back | LAST_INSERT_ID() | RETURNING * |
| Case-insensitive match | LIKE (with default collations) | ILIKE |
None of these take long to learn. Moving an application between the two is usually a matter of adjusting a handful of queries, not rethinking your design.
MySQL is owned by Oracle and offered under the GPL with commercial licences available; MariaDB was forked partly over concerns about that ownership. PostgreSQL is developed by an independent global community under a permissive licence. For most projects using a hosted database, this makes no practical difference - but it explains why many open-source and cloud platforms have standardised on PostgreSQL.