MySQL projects
A MySQL project is a project whose database is MySQL 8.4 instead of Postgres. It shipped in v1.6.0. Everything around the database works the same way: GraphQL and REST are generated from your tables, your app's users sign up and log in through Auth, and permissions decide which rows each caller reaches.
Create a project
- In Studio, create a project (or add a database to an existing one) and pick MySQL as the engine. The card reads "MySQL 8.4, TLS required".
- Choose a MySQL version if the picker offers more than one, and a plan.
- Wait for the project to turn ready, then open the project's connection details to see how to reach the database.
A project holds at most one database, so a project is either Postgres, DocumentDB or MySQL.
Connect
Every MySQL connection requires TLS, and the server certificate is checked against a certificate
authority that belongs to your project alone. Studio shows the connection strings with the right
mode already set, and lets you download the project's CA file (named {projectId}-ca.pem). Public
access is a port an admin opens under Public database port; without it, use the internal
address from a container in the same project.
mysql --host=HOST --port=PORT --user=USER --password \
--ssl-mode=VERIFY_IDENTITY --ssl-ca=proj-xxxxxxxxxx-ca.pem DATABASE
From Node, with mysql2, pass the CA and read the password from the environment:
import { readFileSync } from 'node:fs'
import mysql from 'mysql2/promise'
const connection = await mysql.createConnection({
host: 'HOST',
port: 3306,
user: 'USER',
password: process.env.MYSQL_PASSWORD,
database: 'DATABASE',
ssl: { ca: readFileSync('proj-xxxxxxxxxx-ca.pem') },
})
Java's Connector/J reads a trust store rather than a PEM file; Studio shows the keytool command
that builds one from the CA.
Create a table
Use Database > Tables in Studio, or the SQL editor. This table keeps each row's owner in a column:
CREATE TABLE notes (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
owner_id VARCHAR(64) NOT NULL,
body TEXT NOT NULL
);
The GraphQL and REST APIs pick the table up from the schema. As on Postgres, the API stays closed until you permit it.
Row permissions per user
Set permissions on the table in Studio, the same screen as for Postgres. To let a signed-in user read and write only their own notes:
{
"table": "notes",
"role": "user",
"select": {
"filter": { "owner_id": { "_eq": "X-Excalibase-User-Id" } },
"columns": ["id", "owner_id", "body"]
},
"insert": {
"check": {},
"columns": ["body"],
"set": { "owner_id": "X-Excalibase-User-Id" }
}
}
X-Excalibase-User-Id is the user id in the verified login token. The filter is added to every read
of the table over GraphQL and REST, and set fills owner_id from the token, so a client cannot
write rows as someone else. The permission model is the one described in
Permissions and Row-Level Security. The engine applies these rules itself, so
they do not depend on MySQL having a row-level security feature.
Users sign up and log in
A MySQL project has the same auth routes as any other project: register, login and refresh, under
/auth/{orgSlug}/{projectId}/.... See Auth for the calls. The project's end users are
stored in an auth database inside the project's own MySQL instance, and only the auth service
can read those tables; your app's role and your SQL console cannot. Email addresses compare exactly,
so Alice@example.com and alice@example.com are two accounts.
Call the API
The routes match a Postgres project. Send the user's access token as a bearer token:
curl -s "https://api.excalibase.io/$PROJECT_ID/api/v1/notes" \
-H "Authorization: Bearer $ACCESS_TOKEN"
curl -s -X POST "https://api.excalibase.io/$PROJECT_ID/graphql" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"query":"{ notes { id body } }"}'
See Connect to your project for the full set of calls.
Backups
Backups of a MySQL project are written to object storage. You can restore within the backup window shown on the Backups page in Studio. Point-in-time restore to any second is not available for MySQL projects yet; Postgres projects have it.
Differences from Postgres
- Computed fields are a Postgres feature.
- Point-in-time restore is Postgres only, for now.
- A project's Postgres version choices do not apply; you pick a MySQL version instead.
Self-hosting
Running the engine standalone against your own MySQL is covered in MySQL (standalone engine).