PostgreSQL and MySQL are both mature, free, widely deployed relational databases, and for a beginner’s first project either one works. SQL learned on one transfers almost entirely to the other. The real differences are in the edges: PostgreSQL follows the SQL standard more closely and has richer data types and extensions; MySQL is simpler to administer and runs behind a large share of the web. If you have no reason to pick, learn PostgreSQL; if a job or a framework you are joining uses MySQL, learn that and lose nothing.
What they share#
Tables, rows, columns, primary and foreign keys, indexes, transactions, joins, aggregate functions, views, and the SQL to use them all. A query like this runs unchanged on both:
SELECT c.name, COUNT(o.id) AS orders, SUM(o.total) AS revenue
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE o.placed_at >= '2026-01-01'
GROUP BY c.name
HAVING SUM(o.total) > 1000
ORDER BY revenue DESC
LIMIT 10;
Both are ACID-compliant, both replicate, both back up, both scale far past what a personal project or a small business will need. Both are free and open source. The choice rarely decides whether a project succeeds.
Where PostgreSQL is stronger#
- Standards compliance. It implements the SQL standard more faithfully, so what you learn from a textbook works, and behaviours are less surprising.
- Data types. Arrays, ranges, network addresses, UUIDs, geometric types, and a binary JSON type with indexing and query operators that make it a credible document store as well.
- Extensions. PostGIS for geographic data, pgvector for embeddings and similarity search, full-text search built in, time-series extensions. Adding capability without changing databases.
- Advanced SQL. Window functions, common table expressions, lateral joins and transactional DDL have been solid for longer.
- Concurrency. Its multi-version design handles many simultaneous writers well.
Where MySQL is stronger#
- Simplicity. Fewer knobs, an easier first install, and less to understand about configuration.
- Ubiquity. WordPress, most shared hosting, and a great many existing applications run on it. If you work with PHP web applications, you will meet it constantly.
- Read-heavy simplicity. For straightforward read-mostly workloads it performs well with little tuning.
- Tooling familiarity. Many hosting panels and older tools assume it.
MariaDB, a fork with the same origins, is a drop-in alternative that ships as the default on several Linux distributions.
Differences you will actually notice#
| PostgreSQL | MySQL | |
|---|---|---|
| Case of identifiers | Folded to lower case unless quoted | Depends on the OS file system for table names |
| String quoting | Single quotes only for strings; double quotes are identifiers | Accepts double quotes for strings by default |
| Auto-increment | GENERATED ALWAYS AS IDENTITY or SERIAL |
AUTO_INCREMENT |
| Upsert | INSERT ... ON CONFLICT DO UPDATE |
INSERT ... ON DUPLICATE KEY UPDATE |
| Returning inserted rows | RETURNING * |
Not until recent versions; use last insert id |
| Boolean type | A real boolean |
An alias for tinyint(1) |
| Strictness | Rejects invalid data | Historically coerced or truncated silently; strict mode is now the default |
| Default port | 5432 | 3306 |
The strictness row is the one with consequences. Older MySQL would silently truncate a string that was too long or turn an invalid date into zeros; PostgreSQL has always raised an error. Modern MySQL in strict mode behaves properly, but you will still meet old configurations.
Recommendation#
- No constraints, learning databases: PostgreSQL. Its behaviour matches what you read, and it grows with you into JSON, geography and vectors without a migration.
- PHP and WordPress work, or a hosting plan that only offers one: MySQL, because that is what is there.
- Joining a team: whatever they use.
- A small local tool: neither; SQLite is a single file and needs no server.
Frameworks support both equally: Django, Rails, Laravel, Spring, .NET and every ORM speak to either through a connection string.
Trying both#
docker run -d --name pg -e POSTGRES_PASSWORD=secret -p 5432:5432 postgres:17
docker run -d --name my -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 mysql:9
docker exec -it pg psql -U postgres
docker exec -it my mysql -uroot -psecret
Two containers, two prompts, and you can run the same schema and queries against each. Delete them afterwards with docker rm -f pg my.
Questions people ask#
Is MySQL still free?
The community edition is open source. MariaDB is a fully open fork if licensing concerns you.
Which is faster?
It depends on the workload and tuning. Both are fast enough for the overwhelming majority of applications, and the schema and indexes matter far more than the engine.
Can I switch later?
With an ORM and standard SQL, mostly. Vendor-specific features and subtle behaviours make migrations real work, so the choice is worth a moment’s thought but not a month’s.
What about NoSQL databases?
A different category, for different shapes of data. Learn relational first; most applications are relational, and PostgreSQL’s JSON support covers many of the cases people reach for NoSQL to solve.
Where to go next#
- Working with databases — the concepts.
- “permission denied for table” in PostgreSQL — the first error most people hit.
- What is Docker? — the easiest way to run either.