> ## Documentation Index
> Fetch the complete documentation index at: https://snapr.seshuk.im/llms.txt
> Use this file to discover all available pages before exploring further.

# MySQL

> Back up MySQL databases with mysqldump: single database, all databases, table filters, sockets, and extra flags.

`type: mysql` uses `mysqldump` to produce a logical dump. For MariaDB, use [`type: mariadb`](/configuration/sources/mariadb) instead — it prefers `mariadb-dump` and falls back to `mysqldump`.

## Example

```yaml snapr.yaml theme={null}
sources:
  - type: mysql
    host: db.internal
    port: 3306
    username: backup
    password: env:MYSQL_PASSWORD
    database: app
    excludeTables:
      - sessions
    extraParams:
      single-transaction: ''
      quick: ''
```

## Options

| Option          | Type      | Required | Default     | Description                                                                             |
| --------------- | --------- | -------- | ----------- | --------------------------------------------------------------------------------------- |
| `type`          | `mysql`   | Yes      |             |                                                                                         |
| `host`          | string    | No       | `127.0.0.1` | Ignored when `socket` is set.                                                           |
| `port`          | int       | No       | `3306`      |                                                                                         |
| `socket`        | string    | No       |             | UNIX socket path, an alternative to host/port.                                          |
| `username`      | string    | No       |             | Passed as `-u`.                                                                         |
| `password`      | string    | No       |             | Passed via the `MYSQL_PWD` environment variable, never on the command line. Use `env:`. |
| `database`      | string    | Yes\*    |             | Required unless `allDatabases: true`.                                                   |
| `allDatabases`  | bool      | No       | `false`     | Dump every database on the server (`--all-databases`).                                  |
| `tables`        | string\[] | No       |             | Only dump these tables from `database`.                                                 |
| `excludeTables` | string\[] | No       |             | Each entry becomes `--ignore-table=<db>.<table>`. Single-database mode only.            |
| `extraParams`   | map       | No       |             | Extra `mysqldump` flags.                                                                |

## Requirements

* `mysqldump` must be installed on the snapr host and available in `PATH`. Install it via your distro's `mysql-client` or `default-mysql-client` package.
* The backup user typically needs at minimum `SELECT`, `LOCK TABLES`, `SHOW VIEW`, `EVENT`, `TRIGGER`, and — when dumping replicas or using `--single-transaction` — `PROCESS`.

## Notes

* `extraParams` keys are prefixed with `--`. Use an empty string value for boolean flags.
* `excludeTables` is ignored when `allDatabases: true` is set.

### All databases via socket

```yaml snapr.yaml theme={null}
sources:
  - type: mysql
    socket: /var/run/mysqld/mysqld.sock
    username: backup
    password: env:MYSQL_PASSWORD
    allDatabases: true
```

## Related

* [Sources overview](/configuration/sources/overview)
* [MariaDB source](/configuration/sources/mariadb)
