# GLPI - local to a managed MySQL database

> A short runbook for moving GLPI's database out of a local MySQL container and onto a managed MySQL 8.0 instance

By Zsolt Bizderi · Published 2026-11-27
Canonical: https://ambientnode.uk/glpi-local-to-a-managed-mysql-database

A lot of [GLPI](https://www.glpi-project.org/en/) Docker setups start with a local `mysql` service and a named volume. Moving the database to a managed MySQL instance is mostly a dump and restore, then repointing GLPI at the new host, but you must keep your existing `glpi_data` volume, as that is where GLPI stores its config and its encryption key file. If that volume is not wiped, the database move is straightforward.

## What this guide assumes

* GLPI runs in Docker
* Your current database is a local MySQL container with a named volume.
* Your destination is managed MySQL 8.0.
* You can take a short maintenance window.

## Placeholders

Replace these with your values:

* `<GLPI_CONTAINER>` e.g. `glpi`
* `<LOCAL_DB_CONTAINER>` e.g. `glpi_db`
* `<BACKUP_DIR>` e.g. `/root/glpi-migration`
* `<DB_HOST>` managed DB hostname
* `<DB_PORT>` managed DB port (often not 3306 on managed services)
* `<DB_NAME>` e.g. `GLPI`
* `<DB_USER>` e.g. `glpi_app` or your managed admin user
* `<DB_PASSWORD>` database password

## 1\. Pin your GLPI image version

Do not run `:latest` during a migration. Pin the image tag first so you are not chasing a moving target while you dump and import.

```
services:
  glpi:
    image: diouxx/glpi:<GLPI_VERSION>
```

## 2\. Stop GLPI writes

Stop only the GLPI container. Leave the local DB container running.

```
docker stop <GLPI_CONTAINER>
```

## 3\. Back up volumes

Back up the GLPI volume first. This preserves your config and encryption key.

```
mkdir -p <BACKUP_DIR>
docker run --rm -v glpi_data:/src -v <BACKUP_DIR>:/backup alpine \
  sh -c "cd /src && tar -czf /backup/glpi_data.tar.gz ."
```

Optionally back up the logs:

```
docker run --rm -v glpi_logs:/src -v <BACKUP_DIR>:/backup alpine \
  sh -c "cd /src && tar -czf /backup/glpi_logs.tar.gz ."
```

Optionally back up the old MySQL volume too:

```
docker run --rm -v db_data:/src -v <BACKUP_DIR>:/backup alpine \
  sh -c "cd /src && tar -czf /backup/db_data.tar.gz ."
```

## 4\. Confirm the encryption key exists

On most installs this file lives in the GLPI config directory:

```
docker run --rm -v glpi_data:/mnt alpine \
  sh -lc 'ls -la /mnt/config | grep -E "glpicrypt.key|glpi.key" || true'
```

If you keep the same `glpi_data` volume, the key stays the same after the DB move.

## 5\. Dump the local database

Dump from the local MySQL container:

```
docker exec <LOCAL_DB_CONTAINER> sh -c \
  'mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" --single-transaction --routines --triggers --events --set-gtid-purged=OFF <DB_NAME>' \
  > <BACKUP_DIR>/glpi_dump.sql
```

Double-check it worked:

```
ls -lh <BACKUP_DIR>/glpi_dump.sql
head -n 5 <BACKUP_DIR>/glpi_dump.sql
```

## 6\. Create the database and user on the managed server

Run this on the managed DB, or in its admin UI. Use a dedicated app user where possible.

```
CREATE DATABASE GLPI CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'glpi_app'@'%' IDENTIFIED BY 'STRONGPASSWORD';
GRANT ALL PRIVILEGES ON GLPI.* TO 'glpi_app'@'%';
FLUSH PRIVILEGES;
```

Replace `%` with your server IP or an allowed range if your provider supports it.

## 7\. Import the dump into the managed DB

If you have a `mysql` client on the host:

```
mysql -h <DB_HOST> -P <DB_PORT> -u <DB_USER> -p <DB_NAME> < <BACKUP_DIR>/glpi_dump.sql
```

If you don't have a client installed, use a temporary container:

```
cat <BACKUP_DIR>/glpi_dump.sql | \
  docker run --rm -i mysql:8 mysql -h <DB_HOST> -P <DB_PORT> -u <DB_USER> -p <DB_NAME>
```

Verify the DB exists and has tables:

```
docker run --rm -it mysql:8 mysql -h <DB_HOST> -P <DB_PORT> -u <DB_USER> -p \
  -e "SHOW DATABASES LIKE '<DB_NAME>'; SHOW TABLES FROM \`<DB_NAME>\` LIMIT 5;"
```

## 8\. Update your stack

Remove the local `db:` service and its `db_data:` volume from the stack. Keep `glpi_data` and `glpi_logs`.

```
version: '3.8'

services:
  glpi:
    image: diouxx/glpi:<GLPI_VERSION>
    container_name: glpi
    restart: always
    ports:
      - "8888:80"
    environment:
      TIMEZONE: Europe/London
      GLPI_DB_HOST: <DB_HOST>
      GLPI_DB_PORT: <DB_PORT>
      MYSQL_DATABASE: <DB_NAME>
      MYSQL_USER: <DB_USER>
      MYSQL_PASSWORD: <DB_PASSWORD>
    volumes:
      - glpi_data:/var/www/html/glpi
      - glpi_logs:/var/log/glpi
    networks:
      - glpi_network

volumes:
  glpi_data:
  glpi_logs:

networks:
  glpi_network
```

Deploy the updated stack.

## 9\. Point GLPI at the new host and port

Use GLPI's CLI so the port is applied correctly.

```
docker exec -it <GLPI_CONTAINER> sh -lc '
  cd /var/www/html/glpi &&
  php bin/console db:configure --reconfigure -H "<DB_HOST>" -P <DB_PORT> -d "<DB_NAME>" -u "<DB_USER>" -p
'
```

It prints `Database password:`. Type the password; it will not echo. When it asks whether to continue, answer yes. Then restart GLPI:

```
docker restart <GLPI_CONTAINER>
```

## 10\. Validate

Log in and check the basics:

* Open assets.
* Open the knowledge base.
* Open tickets.
* Create a test ticket and add a follow-up.
* Upload an attachment.

For a fast log check:

```
docker exec -it <GLPI_CONTAINER> sh -lc 'tail -n 50 /var/www/html/glpi/files/_log/php-errors.log'
docker exec -it <GLPI_CONTAINER> sh -lc 'tail -n 50 /var/www/html/glpi/files/_log/sql-errors.log'
```

## Common issues

**Managed DB may use a non-default port.** Many managed services don't use 3306. Set the correct port in both places: `GLPI_DB_PORT` in your stack, and `-P <DB_PORT>` on `php bin/console db:configure`.

**Tickets fail on MySQL 8.0 with `ONLY_FULL_GROUP_BY` enabled.** You may see an error like:

```
Expression #X of SELECT list is not in GROUP BY clause ... sql_mode=only_full_group_by
```

This is MySQL's strict GROUP BY enforcement, and some GLPI plugins trigger it on ticket views. `ONLY_FULL_GROUP_BY` can be enabled indirectly by ANSI (Combination Mode); removing ANSI (Combination Mode) removes it. After changing SQL modes in the provider UI, restart GLPI so it reconnects:

```
docker restart <GLPI_CONTAINER>
```

Verify the mode:

```
docker run --rm -it mysql:8 mysql -h <DB_HOST> -P <DB_PORT> -u <DB_USER> -p \
  -e "SELECT @@GLOBAL.sql_mode\G"
```

## Rollback

If you need to roll back:

1. Redeploy your original stack with the local `db:` service and `db_data` volume.
2. Point GLPI back to `db` as the host.
3. Start the containers.

## Post-migration cleanup

* Use a dedicated DB user for GLPI rather than the managed admin user.
* Restrict DB access by source IP if your provider supports it.
* Keep the backup tarballs until you have a few days of stable operation.
