# Protect MySQL or MariaDB

> Backups, restore to any second, Proof, Rewind and Pulse for MySQL 8.0/8.4 and MariaDB 10.6 to 11.4.

Source: https://rowsafe.sh/docs/guides/mysql

Rowsafe protects MySQL and MariaDB like PostgreSQL: encrypted backups in your bucket, restore to any second, a weekly Proof, Rewind, Marks, Pulse, and the tools to run the server. Under the hood: [How MySQL and MariaDB backups work](https://rowsafe.sh/docs/concepts/mysql).

## Supported versions

| Server  | Versions              | Backup tool                    | Where                                                                                      |
| ------- | --------------------- | ------------------------------ | ------------------------------------------------------------------------------------------ |
| MySQL   | 8.0, 8.4 LTS          | Percona XtraBackup 8.0 / 8.4   | Debian 12/13, Ubuntu 22.04/24.04; Docker (`mysql:8.0`, `mysql:8.4`)                        |
| MariaDB | 10.6, 10.11, 11.4 LTS | mariadb-backup (MariaDB's own) | Debian 12/13, Ubuntu 22.04/24.04; Docker (`mariadb:10.6`, `mariadb:10.11`, `mariadb:11.4`) |

Other versions (MySQL 5.7 and the 9.x innovation releases), Percona Server and Galera clusters aren't supported.

## On a server: one command

Run the install command from **Servers → Add a server** on the database server, as root. The installer:

**Installs the backup tool.** MySQL: Percona XtraBackup matching your server, from Percona's repository (signing key fingerprint checked). MariaDB: `mariadb-backup` from your server's source.

**Runs the agent as the `mysql` user**, to read the data files and start private copies (Proof, Rewind).

**Finds your server** and asks you to name it in Rowsafe.

**Creates Rowsafe's account** `rowsafe@localhost` as root over the local socket. If root has a password, it asks once and doesn't keep it. The account's random password stays on your server. Its rights are [below](#what-rowsafe-may-do).

**Asks what Rowsafe may do** on the server (restarts, updates, pooling, firewall, standbys), each only when someone clicks and confirms.

**Shows the plan** and changes nothing until you say yes. MySQL 8 usually needs nothing. MariaDB needs its binary log turned on: one restart (a few seconds), when you choose.

Then Rowsafe checks changes reach your bucket and takes the first full backup. If you restart yourself, Rowsafe notices and finishes.

> **A server with both PostgreSQL and MySQL:** There the agent runs as `postgres` and can't read MySQL's files, so the installer protects PostgreSQL only.

## In Docker

The agent runs as a sidecar, built on the same official image as your server (so Proof runs the same version). Add a socket volume and one service:

**MySQL**

```yaml
services:
  mysql:
    image: mysql:8.4
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password
    secrets: [mysql_root_password]
    volumes:
      - mysqldata:/var/lib/mysql
      - mysqlsocket:/var/run/mysqld          # Rowsafe

  rowsafe-agent:                             # Rowsafe
    image: ghcr.io/rowsafe/agent:<version>-mysql8.4
    hostname: db-1
    user: "999:999"
    env_file: rowsafe-agent.env
    environment:
      ROWSAFE_MYSQL_ADMIN_PASSWORD_FILE: /run/secrets/mysql_root_password
    secrets: [mysql_root_password]
    volumes:
      - mysqldata:/var/lib/mysql:ro          # same volume, same path, read-only
      - mysqlsocket:/var/run/mysqld
      - rowsafe-state:/var/lib/rowsafe
```

Then: `rowsafe adopt shop --host db-1 --engine mysql`, and approve the plan in the dashboard.

**MariaDB**

```yaml
services:
  mariadb:
    image: mariadb:11.4
    command: --log-bin=mysql-bin --binlog-format=ROW --server-id=1   # Rowsafe
    environment:
      MARIADB_ROOT_PASSWORD_FILE: /run/secrets/mariadb_root_password
    secrets: [mariadb_root_password]
    volumes:
      - mariadbdata:/var/lib/mysql
      - mariadbsocket:/run/mysqld            # Rowsafe

  rowsafe-agent:                             # Rowsafe
    image: ghcr.io/rowsafe/agent:<version>-mariadb11.4
    hostname: db-1
    user: "999:999"
    env_file: rowsafe-agent.env
    environment:
      ROWSAFE_MYSQL_ADMIN_PASSWORD_FILE: /run/secrets/mariadb_root_password
    secrets: [mariadb_root_password]
    volumes:
      - mariadbdata:/var/lib/mysql:ro
      - mariadbsocket:/run/mysqld
      - rowsafe-state:/var/lib/rowsafe
```

Then: `rowsafe adopt cms --host db-1 --engine mariadb`, and approve the plan.

- `rowsafe-agent.env` holds the enrollment token and bucket settings, as in [Run the agent in Docker](https://rowsafe.sh/docs/guides/docker).
- The root password is used once, to create Rowsafe's account.
- Full files: `deploy/docker/compose.mysql.yml` and `compose.mariadb.yml` in the [agent's repository](https://github.com/rowsafe/rowsafe).
- For **Restart**, add the [container control service](https://rowsafe.sh/docs/guides/docker#let-rowsafe-restart-the-container) with `ROWSAFE_CONTROL_SERVICE: mysql` (or your MariaDB service's name).

## What you get

**Rewind and Proof**

- **Backups**: full weekly, differential daily, streamed from the running server, compressed and encrypted on your server.
- **Restore to any second**: the binary log (every change) is copied to your bucket continuously, at most about a minute behind.
- **Proof**: weekly, the latest backup and changes are restored into a private copy, checked (`CHECK TABLE`, row counts), then deleted.
- **[Rewind](https://rowsafe.sh/docs/guides/restore)**: restore a copy at any second or Mark, compare table by table, bring rows back in one click. Or rewind the whole server, with **Undo** for 7 days ([below](#rewind-the-whole-server)).
- **Marks**: named points (`rowsafe mark`, AI agents through MCP), restored to exactly.
- **[Find the moment](https://rowsafe.sh/docs/guides/find-the-moment)**: when rows were deleted or changed, or tables emptied or dropped.
- **[Files](https://rowsafe.sh/docs/guides/files)**: your app's folders (uploads), restored to the same moment.
- **[Second copy](https://rowsafe.sh/docs/guides/second-copy)**: weekly full backups and the binary log in a second bucket too.

**Pulse**

- **[Monitoring](https://rowsafe.sh/docs/guides/monitoring)**: connections, queries, slow queries, lock waits, buffer pool, long transactions, replication delay. Fixes: stop a blocking query or session, rebuild bloated tables (`OPTIMIZE TABLE`), turn on the slow query log.
- **Queries**: the slowest and newly slower statements, from `performance_schema` (values replaced by `?`).
- **[Recommendations](https://rowsafe.sh/docs/guides/recommendations)**: wasteful queries, tables without a primary key, unused and duplicate indexes with **Drop** (online, a Mark first), and new indexes tested on a restored copy, suggested only if at least twice as fast. **Create index** builds it online.
- **[Logs](https://rowsafe.sh/docs/guides/logs)**: the error log and slow query log, values removed on your server.
- **[Security](https://rowsafe.sh/docs/guides/security)**: exposure (also tested from the internet), anonymous or passwordless accounts, admins allowed from anywhere, the `test` database, encryption, unsupported versions, with one-click fixes and the firewall.
- **[Tuning](https://rowsafe.sh/docs/guides/tuning#mysql-and-mariadb)**: the settings that matter, explained, and **Tune for this server**. A Mark first; every change can be undone.

**Run the server**

- **Restart** in the dashboard (or `rowsafe restart`), after you confirm.
- **[Updates](https://rowsafe.sh/docs/guides/updates#mysql-mariadb-mongodb-and-clickhouse)**: new releases of your version (8.0.x, 10.11.x) in one click; major upgrades (MySQL 8.0 to 8.4, MariaDB 10.11 to 11.4) rehearsed on a copy first, undo for 7 days.
- **[Standby servers](https://rowsafe.sh/docs/guides/standby#mysql-and-mariadb)**: a readable replica, promoted in one click (the old primary is made read-only first).
- **[Connection pooling](https://rowsafe.sh/docs/guides/connection-pooling#mysql-and-mariadb-proxysql)**: ProxySQL, installed and managed by Rowsafe.
- **[Fork](https://rowsafe.sh/docs/guides/fork#mysql-and-mariadb)**: a new copy from any second or Mark, in an empty server.
- **[Move in](https://rowsafe.sh/docs/guides/move-in#mysql-and-mariadb)**: from RDS, Aurora, Cloud SQL, Azure or DigitalOcean, with live sync and a switchover.
- **[Databases & users](https://rowsafe.sh/docs/guides/databases-and-users)**: create and remove databases and users (a Mark first). Passwords are made on your server and reach only your browser.
- **Guard**: [preview a migration](https://rowsafe.sh/docs/guides/preview-migrations#other-engines) on a copy, and masked [safe copies](https://rowsafe.sh/docs/guides/safe-copies#other-engines).

## Rewind the whole server

For the worst case (a migration that broke everything), **Rewind the whole database** puts every database back to a second or a Mark:

1. Rowsafe saves a Mark, then restores up to that second into a private copy. The server keeps running.
2. It stops the server, swaps in the restored data and starts it. Seconds; apps get errors meanwhile.
3. The old data stays 7 days: **Undo rewind** or **Delete the old data now**.

If anything fails, the original data goes back. A full backup follows; restores to after the rewind wait for it.

It needs `restart` allowed, `/var/lib/rowsafe` on the same disk as the data directory, and room for a second copy.

## What Rowsafe may do

**Rowsafe's account** (`rowsafe@localhost`) gets what backups, Proof, Rewind, Pulse and the buttons need, each used only when a person clicks and confirms ([full list](https://rowsafe.sh/docs/concepts/mysql#rowsafes-account)):

| Rights                                                                                                                | For                                                                                                                   |
| --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `RELOAD`, `LOCK TABLES`, `PROCESS`, `BACKUP_ADMIN` (MySQL), `REPLICATION CLIENT` (MySQL) / `BINLOG MONITOR` (MariaDB) | backups, the binary log position of a backup or a Mark                                                                |
| `SELECT`, `SHOW VIEW`, `TRIGGER`                                                                                      | Pulse, comparing a copy with production                                                                               |
| `INSERT`, `UPDATE`, `INDEX`                                                                                           | bringing rows back from a copy; creating and dropping the indexes you pick                                            |
| `CONNECTION_ADMIN`                                                                                                    | ending a query or session that blocks others                                                                          |
| `CREATE USER` and the database rights, with `GRANT OPTION`                                                            | [Databases & users](https://rowsafe.sh/docs/guides/databases-and-users). The server's own accounts (root, `mysql.*`) are never changed. |
| `SYSTEM_VARIABLES_ADMIN`, `PERSIST_RO_VARIABLES_ADMIN` (MySQL) / `SUPER` (MariaDB)                                    | [Tuning](https://rowsafe.sh/docs/guides/tuning#mysql-and-mariadb) and turning on the slow query log                                     |

**Standby servers** need more: *Allow standby servers with this server?* (default no; `--mysql-standby`). Yes gives the account `ALL PRIVILEGES WITH GRANT OPTION`, used only to add, promote or remove a standby, fork to an empty server or move a database in. On an empty server, the installer also asks whether to keep it ready for a standby or fork.

**Root decides** what Rowsafe may do on the server itself ([permissions](https://rowsafe.sh/docs/guides/permissions), `sudo rowsafe-allow`):

| Permission                   | Lets Rowsafe                                                                                                                     |
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `restart`                    | restart, stop and start the server: **Restart**, and rewinding the whole server                                                  |
| `updates`                    | install the server's updates and major upgrades (needs `restart`)                                                                |
| `security-updates`, `reboot` | install the server's security updates, and reboot it                                                                             |
| `pooler`                     | install and manage ProxySQL; `sudo rowsafe-allow pooler-target ADDRESS PORT` lets it follow a standby promoted on another server |
| `firewall`                   | limit who can reach the database's port                                                                                          |

Tuning needs no root permission: MySQL uses `SET PERSIST`, MariaDB Rowsafe's own option file (`/etc/rowsafe/mysql/server.cnf`).

## If the server is lost

On a new server with the same version, install the agent with the same bucket settings and passphrase, then restore into an empty folder as the `mysql` user:

```sh
sudo -u mysql sh -c 'set -a; . /etc/rowsafe/agent.env; set +a; exec /opt/rowsafe/rowsafe-agent restore-mysql \
  --engine mysql --database shop --dir /var/lib/mysql-restored --at 2026-09-25T14:04:00Z'
```

Leave out `--at` for the latest change, or use `--mark NAME`. Then start the server on `/var/lib/mysql-restored/data`. Nothing else changes.

## Limits

- **Rewinding the whole server in place** isn't available in Docker, on a server with replicas (a standby included), with SELinux enforcing, when the data directory is on another disk than `/var/lib/rowsafe`, or when InnoDB keeps files outside the data directory. Restore a copy and bring rows back instead.
- **In Docker**, Restart needs the container control service; ProxySQL and a standby's server need the agent on the server; MariaDB Tuning doesn't survive restarts (set it in the container's command). For updates, pull the newest image of the same version and recreate the container.
- **Triggers run** when rows are brought back: MySQL can't turn them off for one session. The result says which tables have triggers.
- **Tables without a primary key** are restored with the database, but can't be compared or brought back row by row.
- **Non-InnoDB tables** (MyISAM, Aria) are locked briefly during backups and can't be restored to an exact second.
- **Encrypted binary logs** (`binlog_encryption`, `encrypt_binlog`) aren't supported.
- **Replicas**: set up backups on the primary; a replica is skipped.
- **Queries need `performance_schema`**, off by default on MariaDB (set `performance_schema = ON`, then restart). Server-side prepared statements aren't in its digests.
- **Index suggestions on MariaDB need the slow query log.** **Turn on the slow query log** (Pulse) keeps it on for MySQL (`SET PERSIST`) but only until restart on MariaDB (`SET GLOBAL`; add `slow_query_log = ON` to the config to keep it). Only single-table statements become ideas. Pulse warns when an unrotated slow log passes 1 GB.
- **Find the moment works to the second**: "just before" restores to the second before, so earlier changes in that second are missing. With `binlog_format = STATEMENT`, only TRUNCATEs and DROPs are found.
- **Forks hold the real data.** Use a [safe copy](https://rowsafe.sh/docs/guides/safe-copies) for masked data.
- **Older installs**: an account created before Databases & users, Tuning or index suggestions can list but not change. Run the install command again once (the dashboard shows it).
- Rowsafe only needs binary log positions, not GTIDs; if GTIDs are on, Marks record them too.
