# Install and connect

> Install the matching pg_mysql, enable its listener and write a row as an application user.

---

LLMS index: [llms.txt](/llms.txt)

---

This walkthrough uses a fresh Linux instance, a local PostgreSQL administrator and a MariaDB `mysql` client. Install the OpenSSL command-line tool for the certificate step. Both ports must be free. At the end, the application owns one schema and can create and read its own tables. The TLS certificate below is for this loopback example.

## Install the matching server and extension {#build}

This example builds the `19.0.1-r4` server and MySQL extension from two local repositories, `pgsty/mimus` in `mimus/` and `pgsty/pg_mysql` in `pg_mysql/`. The candidate branches are pending upload. Run the commands in Bash from their common parent directory. Have the administrator prepare a fresh `/usr/mimus-19` prefix writable by the build user. On Debian 13 the build uses `build-essential`, `git`, `tar`, `bison`, `flex`, `perl` (including FindBin), `pkg-config`, `libicu-dev`, `libssl-dev`, `libreadline-dev` and `zlib1g-dev`.
{#rpm}

```bash
set -euo pipefail
kernel=0d8a551aa12139afd1032eab7d61ac29800ff0e0
ext=1e631f9802c5ae449d6ca93d5326dc5e2e0418df
test "$(git -C mimus rev-parse "$kernel^{tree}")" = 07fbb73680de442e5ed2f7e1b120de21914807b0
test "$(git -C pg_mysql rev-parse "$ext^{tree}")" = 53dd9be3e87bd51174f704c530371e2bb07b724d

BUILD=$(mktemp -d)
PREFIX=/usr/mimus-19
mkdir "$BUILD/kernel" "$BUILD/pg_mysql"
git -C mimus archive "$kernel" | tar -x -C "$BUILD/kernel"
git -C pg_mysql archive "$ext" | tar -x -C "$BUILD/pg_mysql"
(cd "$BUILD/kernel" && ./configure --prefix="$PREFIX" --with-icu --with-ssl=openssl &&
  make -j"${JOBS:-4}" && make install)
make -C "$BUILD/pg_mysql" -j"${JOBS:-4}" PG_CONFIG="$PREFIX/bin/pg_config"
make -C "$BUILD/pg_mysql" PG_CONFIG="$PREFIX/bin/pg_config" install
"$PREFIX/bin/pg_config" --version
ls "$("$PREFIX/bin/pg_config" --sharedir)/extension/pg_mysql.control"
```

Expect `PostgreSQL 19.0` and the installed control file. If the exact kernel is already installed, set `PREFIX` to that installation and skip the kernel archive, configure and make steps. The extension uses its installed server headers and PGXS through `bin/pg_config`. The server account needs read and execute access to the installation. [Kernel and source identities](/docs/mysql/architecture/#identity)

## Initialize, preload and restart {#init}

In a shell running as OS user `postgres`, choose an unused data directory. The native socket uses peer authentication and the TCP loopback entries use SCRAM. Start PostgreSQL once, then enable the second listener. On an existing service, preserve its other preload entries and use its usual restart command.

```bash
export PATH=/usr/mimus-19/bin:$PATH
export PGDATA="$HOME/mimus-mysql-demo" PGHOST=/tmp PGPORT=5432
initdb -D "$PGDATA" -U postgres -E UTF8 --locale=C --auth-local=peer --auth-host=scram-sha-256
pg_ctl -D "$PGDATA" -l "$PGDATA/server.log" -w start
openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj /CN=localhost \
  -addext 'subjectAltName=IP:127.0.0.1,DNS:localhost' \
  -keyout "$PGDATA/server.key" -out "$PGDATA/server.crt"
chmod 600 "$PGDATA/server.key"
cat >> "$PGDATA/postgresql.conf" <<'CONF'
shared_preload_libraries = 'pg_mysql'
listen_addresses = '127.0.0.1'
unix_socket_directories = '/tmp'
mysql.listen_addresses = '127.0.0.1'
mysql.port = 3306
mysql.database = 'postgres'
ssl = on
CONF
pg_ctl -D "$PGDATA" -l "$PGDATA/server.log" -w restart
psql -X -d postgres -c 'SHOW shared_preload_libraries'
```

Expect `pg_mysql`. SQL installation is per PostgreSQL database. Preloading is cluster-wide and takes effect at restart.

## Prepare the database and role in psql {#setup}

From the same shell, run `psql -X -v ON_ERROR_STOP=1 -d postgres`. As the database superuser, enter the following. At the password prompt, choose a password for the new role. The fresh database grants `CONNECT` to `PUBLIC`; if you revoked it, grant `CONNECT ON DATABASE postgres` to `app_user`.

```sql
CREATE EXTENSION pg_mysql;
SELECT extversion FROM pg_extension WHERE extname = 'pg_mysql';
CREATE ROLE app_user LOGIN;
\password app_user
CREATE SCHEMA app AUTHORIZATION app_user;
\q
```

Expect extension version `1.0`. Earlier development builds, including unified RC2, also report `1.0`. To move an application from one of those builds, install into a fresh cluster and restore its application schema and data. Check direct calls to private helper functions before restoring views. Schema ownership gives `app_user` the rights required by this example.

## Write with mysql and read with psql {#query}

In the same OS shell, connect over TCP as the **ordinary database role**. Supply the password just set. If the client runs under another OS account, give it a readable copy of the public certificate and adjust the CA path.

```bash
mysql --protocol=TCP -h 127.0.0.1 -P 3306 -u app_user -p \
  --ssl-ca="$PGDATA/server.crt" --ssl-verify-server-cert app
```

At the `mysql` prompt, run these statements in schema `app`.

```sql
SELECT DATABASE(), @@version, @@version_comment;
SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid();
CREATE TABLE notes (id INT PRIMARY KEY AUTO_INCREMENT, body VARCHAR(40) NOT NULL);
INSERT INTO notes (body) VALUES ('hello');
SELECT id, body FROM notes ORDER BY id;
```

With the default configuration the first query returns `app`, `5.7.32-log` and `mimus`. The TLS check returns `1`, and the last query returns one row, `1 | hello`. Type `exit`, then cross-check on the native port as the database administrator.

```bash
psql -XAt -d postgres -c 'SELECT id, body FROM app.notes ORDER BY id'
# 1|hello
```

## Connect from another host {#remote}

Configure the intended interface, HBA rule, trusted CA and server identity before opening the listener to the application. Oracle MySQL and MariaDB use different TLS option names. [Authentication and TLS](/docs/mysql/reference/authentication/#hba-tls)
{#remote-upgrade}

---

Backlinks:

- [MySQL](/docs/mysql/)
- [Base · PostgreSQL 19.0](/docs/patches/base/)
