← Back to the blog

Joining PostgreSQL and MySQL: 4 ways compared

A very common setup: the application runs on MySQL and the finance or analytics side uses PostgreSQL. Sooner or later someone needs a query that touches both. PostgreSQL has no built-in way to read a MySQL table in a normal query, and MySQL cannot read PostgreSQL either. There are four practical ways around this.

Way 1: a foreign data wrapper (mysql_fdw)

PostgreSQL can expose remote tables through a foreign data wrapper. With the mysql_fdw extension you declare the MySQL server once and then query its tables as if they were local. The data stays live and you keep writing normal SQL.

CREATE EXTENSION mysql_fdw;

CREATE SERVER mysql_sales
  FOREIGN DATA WRAPPER mysql_fdw
  OPTIONS (host '10.0.0.5', port '3306');

CREATE USER MAPPING FOR CURRENT_USER
  SERVER mysql_sales
  OPTIONS (username 'report_ro', password '********');

IMPORT FOREIGN SCHEMA sales
  FROM SERVER mysql_sales INTO public;

SELECT c.name, SUM(o.total)
FROM   public.orders o
JOIN   accounting.customers c ON c.id = o.customer_id
GROUP  BY c.name;

The catch: it needs superuser rights to install the extension, network access from the PostgreSQL server to MySQL, and care with performance. Joins that cannot be pushed down make PostgreSQL pull rows over the network and join them locally. Managed database services often do not allow the extension at all.

Way 2: export to CSV and combine

Export the MySQL table, load it into PostgreSQL (or a spreadsheet) and join there. This works for a one-off question. For a recurring report it means repeating the same manual steps and working with data that is out of date as soon as it is exported.

Way 3: scheduled ETL into one database

Copy the MySQL tables you need into PostgreSQL on a schedule, then query PostgreSQL only. This is robust and fast for readers, and it is the right design when many people or dashboards need the combined data. The cost is building and operating the pipeline and accepting that data is as fresh as the last run.

Way 4: a tool that joins across connections

Connect to both databases from one tool, pick a table from each, define the matching columns and let the tool fetch and join the rows. No extension, no server-to-server network access and no warehouse. It suits reports, reconciliations and checks on moderate volumes.

Gotchas that apply to every approach

  • Types: MySQL tinyint(1) booleans, PostgreSQL boolean and text flags rarely line up; decide on one representation.
  • Collation: MySQL is often case-insensitive for string comparison by default; PostgreSQL is case-sensitive. A key that matches in MySQL may not match in PostgreSQL.
  • Time zones: DATETIME in MySQL has no zone, TIMESTAMPTZ in PostgreSQL does. Agree what the stored value means before comparing days.
  • Character sets: confirm both sides use UTF-8 (utf8mb4 in MySQL) so Thai text survives.

Which should you pick?

  • One question, once: CSV.
  • You control both servers and need live joins in SQL: mysql_fdw.
  • Many consumers, large volumes: ETL into one database.
  • A small team that needs recurring reports without new infrastructure: a cross-connection tool.

Step by step: join PostgreSQL and MySQL on the Join Canvas →

Bring all your databases into one place

Start free, or book a demo and we will walk through it with your own team’s data.