How to Navigate the MySQL Open Source License in PostgreSQL

Galaxy Glossary

What is the MySQL open source license and how does it impact PostgreSQL users?

Shows how the GPL-2 MySQL license differs from PostgreSQL’s permissive license and how to stay compliant when integrating both databases.

Sign up for the latest in SQL knowledge from the Galaxy Team!

Description

What is the MySQL open source license?

The MySQL Community Edition ships under GNU GPL-2. Any software that links to the MySQL server or client libraries and is distributed externally must also be released under a GPL-compatible license, unless you purchase a commercial license from Oracle.

How does the MySQL license differ from PostgreSQL’s?

PostgreSQL uses a permissive, Berkeley-style license. You can modify, embed, and distribute PostgreSQL in closed-source products without releasing your source code. The GPL-2 attached to MySQL imposes reciprocal obligations that the PostgreSQL license does not.

Will using the MySQL license affect my PostgreSQL project?

Running MySQL and PostgreSQL side-by-side is safe. Problems arise only when you statically link MySQL GPL client libraries into proprietary binaries. Accessing a MySQL database from PostgreSQL through a foreign data wrapper (FDW) is considered "mere aggregation" and does not infect your Postgres code with GPL requirements.

How do I query MySQL data from PostgreSQL without violating GPL?

Use the mysql_fdw extension. Because the FDW is licensed under the PostgreSQL License and communicates with MySQL over TCP, your own code remains unaffected by the GPL.

Step-by-step FDW setup

1. Install mysql_fdw.
2. Create the server, user mapping, and foreign tables (see syntax below).
3. Query MySQL tables from PostgreSQL just like native tables.

Best practices for license compliance

Keep MySQL client libraries separate from proprietary binaries, prefer TCP connections over embedded libraries, document external dependencies, and review Oracle’s dual-licensing terms before distribution.

Common mistakes

Embedding libmysqlclient in closed-source apps. This triggers GPL obligations—use dynamic linking or REST/FDW calls instead.

Assuming PostgreSQL’s permissive license covers MySQL code. Each component keeps its own license; audit dependencies individually.

FAQ

Does querying MySQL from Postgres force my code to be GPL?

No. Networked access via FDWs or drivers is usually considered separate work under the GPL.

Can I statically link MySQL client libs if my app is internal only?

Yes, internal use is exempt, but distribution outside your organization triggers GPL requirements.

Why How to Navigate the MySQL Open Source License in PostgreSQL is important

How to Navigate the MySQL Open Source License in PostgreSQL Example Usage


-- Check whether any out-of-stock products were ordered today via MySQL FDW
SELECT p.name, oi.quantity
FROM Orders o
JOIN OrderItems oi ON oi.order_id = o.id
JOIN Products p   ON p.id        = oi.product_id
WHERE o.order_date = CURRENT_DATE
  AND p.stock = 0;

How to Navigate the MySQL Open Source License in PostgreSQL Syntax


-- Install and configure mysql_fdw
CREATE EXTENSION IF NOT EXISTS mysql_fdw;

-- 1️⃣ Define a connection to the MySQL server
CREATE SERVER mysql_ecom
  FOREIGN DATA WRAPPER mysql_fdw
  OPTIONS (host 'mysql_host', port '3306');

-- 2️⃣ Map the PostgreSQL role to a MySQL user
CREATE USER MAPPING FOR app_user
  SERVER mysql_ecom
  OPTIONS (username 'mysql_user', password 'secret');

-- 3️⃣ Import specific MySQL tables into PostgreSQL
IMPORT FOREIGN SCHEMA ecommerce
  LIMIT TO (Customers, Orders, OrderItems, Products)
  FROM SERVER mysql_ecom INTO public;

-- 4️⃣ Query the foreign tables just like native ones
SELECT c.name, SUM(oi.quantity * p.price) AS lifetime_value
FROM Customers c
JOIN Orders o       ON o.customer_id = c.id
JOIN OrderItems oi  ON oi.order_id   = o.id
JOIN Products p     ON p.id          = oi.product_id
GROUP BY c.name
ORDER BY lifetime_value DESC;

Common Mistakes

Frequently Asked Questions (FAQs)

Does using mysql_fdw force my application to be open source?

No. The FDW communicates over TCP, so your code remains independent of the GPL.

Can I mix MySQL GPL and PostgreSQL code in the same repository?

Yes, but distribute them under compatible licenses or clearly separate the GPL parts.

Is Oracle’s commercial MySQL license an alternative?

Yes, purchasing a commercial license removes GPL obligations for distributed software.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo