MySQL vs PostgreSQL

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.

MySQLPostgreSQL
Shared hostingAlmost always includedRarely offered
Managed servicesWidely availableWidely available, plus Neon and Supabase
LicenceGPL (community edition), owned by OraclePostgreSQL licence (permissive)
JSONJSON type with functionsJSONB - binary, indexable
ExtensionsLimitedRich: PostGIS, pgvector and many more
StrictnessStrict by default in modern versionsStrict, with rich types and constraints
Close relativeMariaDB (a compatible fork)-

Where you can run them

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.


Features

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.


SQL differences you'll notice

TaskMySQLPostgreSQL
Auto-incrementing idINT AUTO_INCREMENTGENERATED ALWAYS AS IDENTITY
Quoting identifiers`backticks`"double quotes"
Insert-or-updateON DUPLICATE KEY UPDATEON CONFLICT ... DO UPDATE
Get the inserted row backLAST_INSERT_ID()RETURNING *
Case-insensitive matchLIKE (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.


Licensing and governance

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.


The verdict

  • Choose MySQL if you're on shared hosting, working with PHP applications like WordPress, or joining a team that already runs it. It's fast, proven and everywhere.
  • Choose PostgreSQL for new projects on a VPS, platform service or managed database - especially if you expect to grow, need flexible JSON data alongside tables, or might want extensions like PostGIS or pgvector later.
  • Either way, you're learning SQL, and that skill transfers between them almost entirely.

Take the quiz All comparisons