# Migrate external MariaDB into Kubernetes

In this guide, we will be migrating an external MariaDB into a new `MariaDB` instance running in Kubernetes and managed by MariaDB Enterprise Kubernetes Operator. We will be using [logical backups](/docs/tools/mariadb-enterprise-operator/backup-and-restore/logical_backup.md) for achieving this migration.

{% hint style="info" %}
Ensure you understand the [key considerations and limitations of the Backup and Restore resources](/docs/tools/mariadb-enterprise-operator/backup-and-restore/logical_backup.md#important-considerations-and-limitations) in the MariaDB Enterprise Kubernetes Operator.
{% endhint %}

**1.** Take a logical backup of your external MariaDB using one of the commands below:

```sh
mariadb-dump --user=${MARIADB_USER} --password=${MARIADB_PASSWORD} --host=${MARIADB_HOST} --single-transaction --events --routines --all-databases > backup.2024-08-26T12:24:34Z.sql
```

If you are currently using or migrating to a Galera instance, use the following command instead:

```sh
mariadb-dump --user=${MARIADB_USER} --password=${MARIADB_PASSWORD} --host=${MARIADB_HOST} --single-transaction --events --routines --all-databases --skip-add-locks --ignore-table=mysql.global_priv > backup.2024-08-26T12:24:34Z.sql
```

**2.** Ensure that your backup file matches the following format: `backup.2024-08-26T12:24:34Z.sql`. If the file name does not follow this format, it will be ignored by the operator.

**3.** Upload the backup file to one of the supported [storage types](/docs/tools/mariadb-enterprise-operator/backup-and-restore/logical_backup.md#storage-types). We recommend using S3.

**4.** Create your `MariaDB` resource declaring that you want to [bootstrap from the previous backup](/docs/tools/mariadb-enterprise-operator/backup-and-restore/logical_backup.md#bootstrap-new-mariadb-instances) and providing a [root password Secret](/docs/tools/mariadb-enterprise-operator/backup-and-restore/logical_backup.md#root-credentials) that matches the backup:

```yaml
apiVersion: enterprise.mariadb.com/v1alpha1
kind: MariaDB
metadata:
  name: mariadb-galera
spec:
  rootPasswordSecretKeyRef:
    name: mariadb
    key: root-password
  replicas: 3
  galera:
    enabled: true
  storage:
    size: 1Gi
  bootstrapFrom:
    s3:
      bucket: backups
      prefix: mariadb
      endpoint: minio.minio.svc.cluster.local:9000
      accessKeyIdSecretKeyRef:
        name: minio
        key: access-key-id
      secretAccessKeySecretKeyRef:
        name: minio
        key: secret-access-key
      tls:
        enabled: true
        caSecretKeyRef:
          name: minio-ca
          key: tls.crt
    targetRecoveryTime: 2024-08-26T12:24:34Z
```

**5.** If you are using Galera in your new instance, migrate your previous users and grants to use the `User` and `Grant` CRs. Refer to the [SQL resource documentation](/docs/tools/mariadb-enterprise-operator/sql-resources.md) for further detail.

<sub>*This page is: Copyright © 2025 MariaDB. All rights reserved.*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/tools/mariadb-enterprise-operator/migrations/migrate-external-mariadb-into-kubernetes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
