Skip to content

Shared table across MySQL and PostgreSQL

Enable the MySQL listener on port 3306, write rows from a MySQL client, and query the same table from psql on port 5432.

Preload pg_mysql

Starting from the instance created in Build and start Mimus, preload pg_mysql, enable the MySQL wire listener on port 3306, set a login password, and create the SQL extension inside postgres:

psql -X -d postgres <<'SQL'
ALTER SYSTEM SET shared_preload_libraries = 'pg_mysql';
ALTER SYSTEM SET mysql.listener_on = on;
ALTER SYSTEM SET mysql.port = 3306;
ALTER SYSTEM SET mysql.database = 'postgres';
ALTER ROLE postgres WITH PASSWORD 'ChangeMe_Lab_2026!';
SQL

pg_ctl -D /var/lib/mimus/data restart
psql -X -d postgres -c "CREATE EXTENSION pg_mysql;"

Ensure pg_hba.conf permits local TCP logins (scram-sha-256 or md5) from 127.0.0.1/32.

Create and populate a table from MySQL

Connect with the standard mysql command-line client on TCP 3306, create a logical MySQL database app, and insert two rows:

mysql -h 127.0.0.1 -P 3306 -u postgres -p'ChangeMe_Lab_2026!' <<'SQL'
CREATE DATABASE app;
USE app;
CREATE TABLE notes (
    id   INT PRIMARY KEY AUTO_INCREMENT,
    body VARCHAR(40) NOT NULL
);
INSERT INTO notes (body) VALUES ('written over 3306'), ('shared MVCC row');
SELECT DATABASE(), @@version, @@version_comment;
SQL

Each logical MySQL database maps to a PostgreSQL schema inside mysql.database (postgres by default).

Query the same physical table from PostgreSQL

Now read and join those exact committed rows over native PostgreSQL on port 5432:

psql -X -h 127.0.0.1 -p 5432 -U postgres -d postgres \
  -c "SELECT id, body FROM app.notes ORDER BY id;"
 id |       body
----+-------------------
  1 | written over 3306
  2 | shared MVCC row
(2 rows)

Both sessions share one buffer pool, one WAL stream, and one physical relation (app.notes). For driver details, TLS setup and SQL dialect rules, see the MySQL manual.

Scan to open this page
https://mimus.pgsty.com/docs/tutorials/shared-table/