Skip to main content
This guide runs MySQL 8.4 in a persistent sandbox with its data directory on an Archil disk. MySQL runs as a supervised service, listens on a public hostname, and only accepts encrypted connections from a user with a password. You connect from your own machine with the mysql client, write some rows, stop the sandbox, and read them back. MySQL doesn’t need to know anything about Archil. It reads and writes files in its data directory as usual, and Archil keeps them durable in object storage, so the database outlives any one sandbox.

Prerequisites

Export your Archil API key and a region where sandboxes are available (aws-us-east-1, aws-us-west-2, or aws-eu-west-1):
Then install the SDK:
On your machine you also need the mysql client and socat, which carries the connection over TLS to the sandbox:
Finally, generate a password. The setup script gives it to MySQL’s root user and to an app user, and the mysql client reads it later:

Write the setup script

This script runs inside the sandbox. The Archil disk is mounted by root, and MySQL runs as the mysql user, so the script hands the data directory over first. On an empty disk it then initializes MySQL with an init file that sets the root password, creates an app database, and creates an app user that can connect from anywhere with the password. Finally, it registers MySQL as a service, which restarts if it crashes and starts again whenever the sandbox boots. --require-secure-transport makes MySQL reject network connections that don’t use TLS; the server generates its own certificate during initialization.
setup.sh
Because the script only initializes an empty data directory, you can run it on a new sandbox that mounts an existing mysql-data disk, and it just starts the server on the data that’s already there.

Start the database

The next script creates a disk, creates a sandbox from the official mysql:8.4 image with the disk mounted at /mnt/archil, uploads setup.sh, and runs it with your password. Then it exposes port 3306 publicly and prints the hostname.
An exposed port is reachable by anyone who knows the hostname. The app user accepts connections from any address, so keep its password long and random, as generated above, and never create a remote MySQL user with a weak password or none.

Connect from your machine

Archil serves public ports over TLS on port 443 with a publicly trusted certificate, and forwards the decrypted TCP stream to the sandbox. The mysql client can’t open that kind of TLS connection on its own, so start a local socat tunnel that listens on port 13306, wraps each connection in TLS, and verifies Archil’s certificate. Use the hostname that create printed:
socat may print a warning that it doesn’t check certificate revocation lists; the tunnel still verifies the certificate. Now connect through the tunnel as the app user. Use 127.0.0.1 rather than localhost, which the mysql client treats as a local socket. --ssl-mode=REQUIRED makes MySQL encrypt the stream inside the tunnel, too, so it stays encrypted all the way to the server:

Stop it and let a connection wake it

A stopped sandbox doesn’t use compute, and a connection to its public port starts it again. Stop the sandbox:
Stopping sends SIGTERM to MySQL, which shuts down cleanly. Query the table again through the same tunnel:
The connection booted the sandbox, which mounted the disk and started the mysql service before answering, in a few seconds. The rows were on the Archil disk the whole time. With MySQL’s default settings, InnoDB flushes its redo log to the Archil disk on every commit, so a committed transaction survives a crash, too.

Clean up

Stop the tunnel, then stop and delete the sandbox and delete the disk:

Next steps

Persistent sandboxes

Lifecycle, services, network access, and forking in detail.

PostgreSQL

Run PostgreSQL the same way, with its data directory on an Archil disk.

Sharing disks

Mount modes, and reading a disk from several machines.

TypeScript SDK

Full reference for sandboxes, disks, and serverless execution.